Note that there are some explanatory texts on larger screens.

plurals
  1. POdo not partial view loads from the parent view
    text
    copied!<p>I have a parent view and a partial view, but when it try to load the partial view from the parent view get the following error</p> <p>The model item passed into the dictionary is of type 'System.Data.Objects.DataClasses.EntityCollection`1[RolMVC3.Models.OFFICE]',but this dictionary requires a model item of type 'RolMVC3.Models.OFFICE'.</p> <p>partial view:</p> <pre><code>@model RolMVC3.Models.OFFICE @Html.HiddenFor(model =&gt; model.IdOffice) @Html.HiddenFor(model =&gt; model.IdSCampus) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.AddressOffice) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.AddressOffice) @Html.ValidationMessageFor(model =&gt; model.AddressOffice) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.PhoneOffice) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model..PhoneOffice) @Html.ValidationMessageFor(model =&gt; model..PhoneOffice) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.EmailOffice) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.EmailOffice) @Html.ValidationMessageFor(model =&gt; EmailOffice) &lt;/div&gt; </code></pre> <p>parent view:</p> <pre><code>@model RolMVC3.Models.CAMPUS_UNIVERSITY @{ ViewBag.Title = "Edit"; } &lt;h2&gt;Edit&lt;/h2&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;h2&gt; @ViewBag.University.Name - @ViewBag.Campus.NameCity &lt;/h2&gt; &lt;fieldset&gt; &lt;legend&gt;MODIFY OFFICE&lt;/legend&gt; @Html.HiddenFor(model =&gt; model.IdUniversidty) @Html.HiddenFor(model =&gt; model.IdCityCampus) @Html.HiddenFor(model =&gt; model.IdCampus) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.AddressCampus) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.AddressCampus) @Html.ValidationMessageFor(model =&gt; model.AddressCampus) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.PhoneCampusSede) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.PhoneCampus) @Html.ValidationMessageFor(model =&gt; model.PhoneCampus) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.EamailCampus) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.EamailCampus) @Html.ValidationMessageFor(model =&gt; model.EamailCampus) &lt;/div&gt; &lt;fieldset&gt; &lt;legend&gt;DATA&lt;/legend&gt; @Html.Partial("_Office", Model.OFFICE) &lt;/fieldset&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } </code></pre> <p>controller:</p> <pre><code> public ActionResult Edit() { decimal id; id = (decimal)Session["Offi"]; ViewBag.University = (from c in db.OFFICE join s in db.CAMPUS_UNIVERSITY on c.IdCampus equals s.IdCampus join u in db.UNIVERSIDTY on s.IdUniversity equals u.IdUniversity where c.IdOffice == id select u).Single(); ViewBag.Campus = (from c in db.OFFICE join s in db.CAMPUS_UNIVERSITY on c.IdCampus equals s.IdCampus join ci in db.CIUDAD on s.IdCaityCampus equals ci.IdCity where c.IdOffice == id select ci).Single(); OFFICE office = db.OFFICE.Single(c =&gt; c.IdOffice == id); CAMPUS_UNIVERSITY campus_university = db.CAMPUS_UNIVERSITY.Single(s =&gt; s.IdSede == office.IdCampus); return View(campus_university); } </code></pre> <p>blessings</p>
 

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