3

I'm getting this troublesome error in my view:

The model item passed into the dictionary is of type 'ContactWeb.Models.ContactListViewModel', but this dictionary requires a model item of type 'ContactWebLibrary.Contact'.

on this line of code: @{Html.RenderPartial("Form");}

I'm using @model ContactWeb.Models.ContactListViewModel at the top of this file.

Here's my view:

 @model ContactWeb.Models.ContactListViewModel

 <h2>Edit</h2>

 @{Html.RenderPartial("Form");}

 @using (Html.BeginForm())
 {
    <fieldset>
    <legend>Select roles for this user:</legend>
    <ul>
    @foreach(var role in Model.AllRoles)
    {
        <li><input name="Roles" type="checkbox" value="@role" />@role</li>
    }
    </ul>
    <input type="submit" />
    </fieldset>
}
integral100x
  • 332
  • 6
  • 20
  • 47

1 Answers1

10

The error tells you have to pass the right model to the Partial View.
Because you didn't pass anything, the MVC framework uses the default model which is the view which called to the Partial model.

This will solve things out:

@{Html.RenderPartial("Form", new ContactWebLibrary.Contact());}

It has nothing to do with RenderPartial VS Partial.

gdoron
  • 147,333
  • 58
  • 291
  • 367
  • Good explanation on what happens when null is passed to the view. I was getting odd messages that I was passing the wrong model. – JasonCoder Aug 02 '13 at 14:26