I found a weird script that prevents bool? correctly sent back to the controller. This is a very specific problem, so follow the instructions to recreate.
The application must be deployed as a virtual folder in IIS, so that instead of / Home / Test URL / Virtual / Home / Test.
Home controller:
[HttpGet] public ActionResult Test(int? temp, bool? testBool) { return View(testBool); }
/ Home / Testing (Razor cshtml):
@model bool? @{ ViewBag.Title = "Test"; } @using (Html.BeginForm("Test", "Home", FormMethod.Get)) { @Html.CheckBox("testBool", Model ?? false, new { onchange = "this.form.submit();" }) @Html.Label(Model == true ? "True" : "False") }
In response to a question about bool? doesn't get to the controller due to int? in front of it in the parameter list. Can this be solved by installing bool? before int? in the parameter list, but obviously you don't need to do this. It also works great if not in a virtual folder in IIS. The same problem exists when using the POST method, although you send bool instead of bool? It works, but is not necessary, if not in a virtual folder, so you do not need to do this either.
Has anyone else experienced this and is there anything that explains why the binding is failing or is it just a bug in MVC3?
If this is just an error, does anyone know what are the proper ASP.Net MVC channels for reporting error messages?
Update:
I found that if there are any number of variables with a zero value in the action parameters, only the first one will work, and all the rest will not be filled. Does anyone know if this is a design or bug?
Chris snowden
source share