model-binding

How to pass IEnumerable list to controller in MVC including checkbox state?

强颜欢笑 提交于 2019-11-26 02:09:21
问题 I have an mvc application in which I am using a model like this: public class BlockedIPViewModel { public string IP { get; set; } public int ID { get; set; } public bool Checked { get; set; } } Now I have a View to bind a list like this: @model IEnumerable<OnlineLotto.Web.Models.BlockedIPViewModel> @using (Html.BeginForm()) { @Html.AntiForgeryToken() } @foreach (var item in Model) { <tr> <td> @Html.HiddenFor(x => item.IP) @Html.CheckBoxFor(x => item.Checked) </td> <td> @Html.DisplayFor

Polymorphic model binding

时光怂恿深爱的人放手 提交于 2019-11-26 01:29:37
问题 This question has been asked before in earlier versions of MVC. There is also this blog entry about a way to work around the problem. I\'m wondering if MVC3 has introduced anything that might help, or if there are any other options. In a nutshell. Here\'s the situation. I have an abstract base model, and 2 concrete subclasses. I have a strongly typed view that renders the models with EditorForModel() . Then I have custom templates to render each concrete type. The problem comes at post time.

ViewModel with List<BaseClass> and editor templates

南笙酒味 提交于 2019-11-26 00:59:31
问题 I have a view that lists tables being added to a floor plan. Tables derive from TableInputModel to allow for RectangleTableInputModel , CircleTableInputModel , etc The ViewModel has a list of TableInputModel which are all one of the derived types. I have a partial view for each of the derived types and given a List of mixed derived types the framework knows how to render them. However, on submitting the form the type information is lost. I have tried with a custom model binder but because the

ASP.NET MVC Binding to a dictionary

倾然丶 夕夏残阳落幕 提交于 2019-11-26 00:59:26
问题 I\'m trying to bind dictionary values within MVC. Within the action I have: model.Params = new Dictionary<string, string>(); model.Params.Add(\"Value1\", \"1\"); model.Params.Add(\"Value2\", \"2\"); model.Params.Add(\"Value3\", \"3\"); and within the view I have: @foreach (KeyValuePair<string, string> kvp in Model.Params) { <tr> <td> <input type=\"hidden\" name=\"Params.Key\" value=\"@kvp.Key\" /> @Html.TextBox(\"Params[\" + kvp.Key + \"]\") </td> </tr> } But the view doesn\'t display the

ASP.NET MVC Binding to a dictionary

拜拜、爱过 提交于 2019-11-25 21:56:49
I'm trying to bind dictionary values within MVC. Within the action I have: model.Params = new Dictionary<string, string>(); model.Params.Add("Value1", "1"); model.Params.Add("Value2", "2"); model.Params.Add("Value3", "3"); and within the view I have: @foreach (KeyValuePair<string, string> kvp in Model.Params) { <tr> <td> <input type="hidden" name="Params.Key" value="@kvp.Key" /> @Html.TextBox("Params[" + kvp.Key + "]") </td> </tr> } But the view doesn't display the initial values, and when the form is submitted the Params property is null? you should take a look to this post from scott

A Partial View passing a collection using the Html.BeginCollectionItem helper

陌路散爱 提交于 2019-11-25 21:53:42
问题 I made a small project to understand the answer from Stephen Muecke here: Submit same Partial View called multiple times data to controller? Almost everything works. The javascript adds new fields from the Partial View, and I can tell they\'re bound to the model by the \"temp\" values inserted by the controller method for the partial view. However, when I submit the new fields the AddRecord() method throws an exception showing that the model isn\'t getting passed in (\"Object reference not

ViewModel with List<BaseClass> and editor templates

风流意气都作罢 提交于 2019-11-25 21:50:48
I have a view that lists tables being added to a floor plan. Tables derive from TableInputModel to allow for RectangleTableInputModel , CircleTableInputModel , etc The ViewModel has a list of TableInputModel which are all one of the derived types. I have a partial view for each of the derived types and given a List of mixed derived types the framework knows how to render them. However, on submitting the form the type information is lost. I have tried with a custom model binder but because the type info is lost when it's being submitted, it wont work... Has anyone tried this before? Assuming