TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sneha K
1.2k
527
195.8k
Radio buttons is not saving the value inDB in MVC4?
Feb 8 2016 11:32 PM
Hi have 2 fields each field contain two radio buttons. when i select the radio butto and trying to save the value of Radio button in Db it always save the value is zero. its not working correctly.
This is my Fields
PaymentReceived
and
PaymentType
. Here i wrote j query coding . if i select the
POVisit
as
Payment
the
PaymentReceived
Radio button will appear and If i select the
PaymentReceived
as
Yes
it will show the
PaymentType
radio button Field and If i select
Cash
in
PaymentType
it will show the respective field otherwise all to be in hide mode.
My View Code
<div id ="PaymentReceived">
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.PaymentReceived, new { @class = "control-label" })
@Html.RadioButton("PaymentReceived", 1) Yes
@Html.RadioButton("PaymentReceived", 0) No
</div>
</div>
</div>
<div id ="PaymentType">
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.PaymentType, new { @class = "control-label" })
@Html.RadioButton("PaymentType", 1) Cash
@Html.RadioButton("PaymentType", 0) Cheque
</div>
</div>
</div>
My Controller code
if (visitorviewmodel.PaymentReceived == true)
visitorviewmodel .PaymentReceived = true;
else
visitorviewmodel.PaymentReceived = false;
if (visitorviewmodel.PaymentType == true)
visitorviewmodel.PaymentType = true;
else
visitorviewmodel.PaymentType = false;
var VisitorsViewObj = new VisitorsForm()
{
PaymentReceived = Convert.ToBoolean(visitorviewmodel.PaymentReceived),
PaymentType= Convert.ToBoolean(visitorviewmodel.PaymentType),
};
if i select
Yes
in Payment received It will show the value as
False
in
if (visitorviewmodel.PaymentReceived == true)
if i select
No
in PaymentReceived it will show the value as false in if statement same as like for Payment type what ever i select the value in radio button it always show the value as false. now what i want is i want to save the value as per selected in radio button . that is if i select yes means it will save the value as 1 in DB if i select the value as no it have to save the value as 0 in DB. please any one help me to solve this problem.
Reply
Answers (
9
)
MVC Execution error
Progress Bar in ASP.Net