Note that there are some explanatory texts on larger screens.

plurals
  1. PONested Partial view passing sub object issue
    primarykey
    data
    text
    <p>I am trying to pass sub object in a partial view to another, and I always get the error. Can anyone help me to solve this? T.T </p> <p>"The model item passed into the dictionary is of type 'Application.Models.PetModel', but this dictionary requires a model item of type 'Application.Models.Calendar'"</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 int Day { get; set; } public int Month { get; set; } public int Year { get; set; } public DateTime DateObj { get { if (Day != 0 &amp;&amp; Month != 0 &amp;&amp; Year != 0) { return new DateTime(Year, Month, Day); } return DateTime.Now; } set { if (value != null) { Day = value.Day; Month = value.Month; Year = value.Year; } } } } </code></pre> <p><strong>Main View</strong></p> <pre><code>@model Application.Models.PetModel @using (Html.BeginForm("CatchPetContent", "Quote",Model)) { @Html.Partial("PetDetailsContent", Model) &lt;input type="submit" value="submit" /&gt; } </code></pre> <p><strong>PetDetailsContent Partial View</strong></p> <pre><code>@model Application.Models.PetModel @Html.TextBoxFor(x =&gt; x.Name) @Html.DropDownListFor(x =&gt; x.SpeciesID, (IEnumerable&lt;SelectListItem&gt;)ViewData["TypeList"], "--Please Select--") @Html.DropDownListFor(x =&gt; x.BreedID, (IEnumerable&lt;SelectListItem&gt;)ViewData["BreedList"], "--Please Select--") @Html.RenderPartial("UserControl/Calendar", Model.DOB) </code></pre> <p><strong>Calendar Partial view</strong></p> <pre><code>@model Application.Models.Calendar @Html.TextBoxFor(x =&gt; x.Day) @Html.TextBoxFor(x =&gt; x.Month) @Html.TextBoxFor(x =&gt; x.Year) </code></pre>
    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.
    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