Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn model from Partial View issue
    primarykey
    data
    text
    <p>I have created a partial view (even though the editor template), I pass a sub model to the view, however, when I clicked "submit", I always get "null" from the partial view. I can get Main model's properties values except the sub model one.</p> <p><strong>Main Model</strong></p> <pre><code>public class PetModel { public string name {get; set;} public long SpeciesID {get; set;} public long BreedID {get; set;} public Calendar DOB {get; set;} } </code></pre> <p><strong>Sub Model</strong></p> <pre><code>public class Calendar { public string Year{get; set;} public string Month{get; set;} public string Day{get; set;} } </code></pre> <p><strong>Main View</strong></p> <pre><code> @model Application.Models.PetModel @using (Html.BeginForm("CatchPetContent", "Quote",Model)) { @Html.TextBoxFor(x =&gt; x.Name) @Html.DropDownListFor(x=&gt;x.SpeciesID,new List&lt;SelectListItem&gt;(),"select") @Html.DropDownListFor(x=&gt;x.BreedID,new List&lt;SelectListItem&gt;(),"select") @Html.EditorFor(Model =&gt; x.DOB) &lt;input type="submit" value="submit" /&gt; } </code></pre> <p><strong>Editor template</strong></p> <pre><code>@model Application.Models.Calendar @Html.DropDownListFor(Model =&gt; Model.Day, new List&lt;SelectListItem&gt;()) @Html.DropDownListFor(Model =&gt; Model.Month,new List&lt;SelectListItem&gt;()) @Html.DropDownListFor(Model =&gt; Model.Year, new List&lt;SelectListItem&gt;()) </code></pre> <p><strong>"CatchPetContent" action</strong></p> <pre><code>[HttpPost] public ActionResult CatchPetContent(PetModel Model) { PetModel pet = new PetModel(); pet.Name = Model.Name; pet.SpeciesID = Model.SpeciesID; pet.BreedID = Model.BreedID; pet.DOB = Model.DOB;// always null RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary(); redirectTargetDictionary.Add("Controller", "Home"); redirectTargetDictionary.Add("Action", "Index"); return new RedirectToRouteResult(new RouteValueDictionary(redirectTargetDictionary)); } </code></pre> <p>When I debugged it, "Model.DOB" is always null</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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