Click here to Skip to main content
16,005,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have radio button when i checked radio1 that time 3 storing into database and when checked radio2 then 2value store into database now i want to edit record and i want show radiobutton checked if data availble aginst those radio button.i am using mvc with razor. plz help me?
Posted
Updated 7-Apr-14 21:01pm
v3

1 solution

Solution: Do like this:

Model:
C#
public class MyViewModel
{
    public bool IsFemale { get; set; }
}


Controller:
SQL
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel
        {
            IsFemale = true
        });
    }

    [HttpPost]
    public ActionResult Index(MyViewModel model)
    {
        return Content("IsFemale: " + model.IsFemale);
    }
}


Model:
HTML
@model MyViewModel

@using (Html.BeginForm())
{
    @Html.RadioButtonFor(model => model.IsFemale, "false", new { id = "male" }) 
    @Html.Label("male", "Male")

    @Html.RadioButtonFor(model => model.IsFemale, "true", new { id = "female" })
    @Html.Label("female", "Female")
    <button type="submit">OK</button>
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900