Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding model with child list MVC 3 razor
    primarykey
    data
    text
    <p>I have the following model :</p> <pre><code> public class ContratoDetailsViewModel { [StringLength(50)] [RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$")] [DisplayName("E-Mail Adm.")] public string emailAdm { get; set; } } public class ContratoDetailContainerViewModel { public ContratoDetailsViewModel contrato { get; set; } public IList&lt;ContratoModels.CCasinoViewModel&gt; ccasinos { get; set; } } public class CCasinoViewModel { public short codigo { get; set; } public List&lt;SelectListItem&gt; listCasinos { get; set; } } </code></pre> <p>the following view :</p> <pre><code>@model ContratoModels.ContratoDetailContainerViewModel @{ ... } @using (Html.BeginForm(new { currentaction = ViewBag.mode })) { ... @Html.EditorFor(m =&gt; m.contrato.emailAdm, state1)&lt;br /&gt; @Html.EditorFor(m =&gt; m.ccasinos,"test") &lt;input type="submit" value="Save" /&gt; } </code></pre> <p>in the folder "EditorTemplates" i have a template called "test.cshtml" :</p> <pre><code>@model List&lt;ContratoModels.CCasinoViewModel&gt; @for (int i = 0; i &lt; Model.Count(); i++) { @Html.DropDownListFor(m =&gt; m[i].codigo,Model[i].listCasinos) } </code></pre> <p>My Controller post action is like this :</p> <pre><code>[HttpPost] public ActionResult Details(ContratoModels.ContratoDetailContainerViewModel model, FormCollection form) { var contrato = model.contrato; var casinos = model.ccasinos; } </code></pre> <p>Before send the view ccasinos,codigo and listCasinos are initialised when i am in debug mode i see the value of them... the form display work like a charm. BUT ... when i submit the form the model.ccasinos is always null !! why ? thank you very much for your reply.</p> <p>note : I use a EditorFor with the child of my main model but if there is a better solution for display and submit with MCV 3 I am interested ...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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