Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 RadioButtonFor value is not binded to the model
    text
    copied!<p>I have a MVC3 Razor form. It have a radiobutton list and some another text fields. When I press submit controller post action get the view model, which have all fields seted correctly, except RegionID.</p> <p><strong>Model:</strong></p> <pre><code> namespace SSHS.Models.RecorderModels { public class CreateViewModel { ... public int RegionID { get; set; } ... } } </code></pre> <p><strong>Controller:</strong></p> <pre><code> namespace SSHS.Controllers { public class RecorderController : Controller { ... public ActionResult Create() { EntrantDBEntities db = new EntrantDBEntities(); List Regions = new List(db.Region); List Schools = new List(db.School); List Settlements = new List(db.settlement); CreateViewModel newEntr = new CreateViewModel(); ViewBag.Regions = Regions; ViewBag.Schools = Schools; ViewBag.Settlements = Settlements; return View(newEntr); } [HttpPost] public ActionResult Create(CreateViewModel m) { EntrantDBEntities db = new EntrantDBEntities(); Entrant e = new Entrant() { FatherName = m.FatherName, Lastname = m.LastName, LocalAddress = m.LocalAddress, Name = m.Name, RegionID = m.RegionID, PassportID = m.PassportID, SchoolID = m.SchoolID, SettlementID = m.SattlementID, TaxID = m.TaxID, }; db.Entrant.AddObject(e); db.SaveChanges(); return RedirectToAction("Index"); } } </code></pre> <p><strong>View:</strong></p> <pre><code> @model SSHS.Models.RecorderModels.CreateViewModel @using SSHS.Models @using (Html.BeginForm("Create", "Recorder", FormMethod.Post)) { @foreach (Region item in ViewBag.Regions) { @Html.RadioButtonFor(m => m.RegionID, item.RegionID) @Html.Label(item.RegionName) - @item.RegionID } ... ... }</code></pre> <p>The Create(CreateViewModel m) method gets data from all textboxes normaly, but RegionID always is 0.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload