Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: ASP.NET MVC 4 model binding issue [665]

$
0
0
Hello,

Recently I updated MVC3 project to MVC4 and I found a strange behavor of default model binder. In some cases he can't bind form parameters to collections of my viewmodel. I built a project for demonstration this problem.

My viewmodel classes:

public class DefaultViewModel
{
public int Id { get; set; }
public List<PickerItem> Rights { get; set; }
public string RightsComment { get; set; }
}

public class PickerItem
{
public string Name { get; set; }
public string Value { get; set; }
}

In the view:

@using (Html.BeginForm("Index", "Home"))
{
<input type="text" name="Id" value="1" />

<input type="text" name="Rights[0].Name" value="Some name 1" />
<input type="text" name="Rights[0].Value" value="Some value 1" />

<input type="text" name="RightsComment" value="Some comment" />
<input type="submit" value="Submit" />
}

Controller action:

[HttpPost]
public ActionResult Index(DefaultViewModel model)
{
if (model.Rights == null)
throw new OperationCanceledException("Property Rights was not binded");
return RedirectToAction("Index");
}

Model binder skip Rights property collection in this case. Moreover, if I delete 'id' input from the form the binding will be correct...

I attach the project that demonstrates this problem
Comments: Verified.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>