Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7703843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:33:04+00:00 2026-05-31T23:33:04+00:00

I have a parent view and a partial view, but when it try to

  • 0

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

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’.

partial view:

@model RolMVC3.Models.OFFICE
        @Html.HiddenFor(model => model.IdOffice)
        @Html.HiddenFor(model => model.IdSCampus)
        <div class="editor-label">
            @Html.LabelFor(model => model.AddressOffice)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.AddressOffice)
            @Html.ValidationMessageFor(model => model.AddressOffice)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PhoneOffice)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model..PhoneOffice)
            @Html.ValidationMessageFor(model => model..PhoneOffice)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EmailOffice)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmailOffice)
            @Html.ValidationMessageFor(model => EmailOffice)
        </div>

parent view:

@model RolMVC3.Models.CAMPUS_UNIVERSITY

@{
    ViewBag.Title = "Edit"; 
}

<h2>Edit</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

   <h2> @ViewBag.University.Name - @ViewBag.Campus.NameCity </h2>

    <fieldset>
        <legend>MODIFY OFFICE</legend>

        @Html.HiddenFor(model => model.IdUniversidty)

        @Html.HiddenFor(model => model.IdCityCampus)

        @Html.HiddenFor(model => model.IdCampus)

        <div class="editor-label">
            @Html.LabelFor(model => model.AddressCampus)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.AddressCampus)
            @Html.ValidationMessageFor(model => model.AddressCampus)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PhoneCampusSede)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PhoneCampus)
            @Html.ValidationMessageFor(model => model.PhoneCampus)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EamailCampus)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EamailCampus)
            @Html.ValidationMessageFor(model => model.EamailCampus)
        </div>

        <fieldset>
        <legend>DATA</legend>
       @Html.Partial("_Office", Model.OFFICE)
        </fieldset>
          <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

controller:

 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 => c.IdOffice == id);

            CAMPUS_UNIVERSITY campus_university = db.CAMPUS_UNIVERSITY.Single(s => s.IdSede == office.IdCampus);


            return View(campus_university);
        }

blessings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:33:05+00:00Added an answer on May 31, 2026 at 11:33 pm

    Your controller has the code

    OFFICE office = db.OFFICE.Single(c => c.IdOffice == id); 
    CAMPUS_UNIVERSITY campus_university = db.CAMPUS_UNIVERSITY
                                            .Single(s => s.IdSede == office.IdCampus); 
    

    But your View is ONLY using the model CAMPUS_UNIVERSITY. I would assume that the CAMPUS_UNIVERSITY.Office property is a EntityCollection<OFFICE> which does not match the view’s requirement of Office.

    One solution is to display all the offices:

    @foreach(var office in Model.OFFICE)
    {
       @Html.Partial("_Office", office)   
    }
    

    or the other is to actually use the Office you created in the controller

    Controller (add)

    ViewBag.Office = db.OFFICE.Single(c => c.IdOffice == id);         
    

    View (change)

    @Html.Partial("_Office", ViewBag.Office)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view that inherits from ViewUserControl<Guid?> - i.e. it's model is
I have a parent-child view model object structure set up and need to update
I have a partial view called '_comment.erb', and it may be called by parent
I have a case where the child view sends notification to its parent view.
I have written a partial view that displays a list of rows, where some
I have parent view that also renders sub-controller action using RenderAction() (that returns a
I have a partial view taskrow that will return a table row, I am
I’m developing MVC application and I have following classes in my model: public class
In Interface Builder I have one parent view and a subview under this. I
If I have a parent view controller that displays a modal view with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.