Hi guys,
I want to insert selected radio button value to database with other field .
Suppose i have a table Tab1(Id ,Gender). How to do it using MVC3 with razor view.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted Apr 14, 2015, 1:08 PM
VIEW :
<%using (Html.BeginForm())
{ %>
<%=Html.RadioButton("Gender", true) %>Male
<%=Html.RadioButton("Gender",false) %>Female
<%} %>
MODEL :
public class HomeModel
{
public int Id{get; set;}
public bool Gender{get; set;}
}
CONTROLLER :
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HomeModel hm)
{
var gen = "N";
if (hm.Gender ==true)
gen = "M";
else
gen = "F";
Tab1 obj = new Tab1();
obj.Id = 1; // Your id
obj.Gender = gen;
// Your Save Logic goes here
return View();
}