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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted Apr 14, 2015, 9:08 AM EDT
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();
}