1

Below one is my UI View Page:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Person>" %> 

Now, I am adding the User control , which use Register Model for displaying content.

<asp:Content ID="Content3" ContentPlaceHolderID="MyControl" runat="server">
    <%Html.RenderPartial("RegisterControl"); %>
</asp:Content>

I am getting error:

The model item passed into the dictionary is of type 'MvcApplication1.Models.Person', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcApplication1.Models.RegisterModels]'.

Please help me here...what I need to do ...??

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122
user1661171
  • 45
  • 1
  • 4
  • Can you show you code in controller too? Are you sure that the model required between your page and partial view has same model required? – cpoDesign Sep 17 '12 at 08:00

2 Answers2

0

You should pass model to your view.

<%Html.RenderPartial("RegisterControl", new MvcApplication1.Models.Person()); %>

More information here:renderpartial with null model gets passed the wrong type

Community
  • 1
  • 1
griZZZly8
  • 694
  • 9
  • 24
0

Your issue here is that your parent view is strongly typed to Person. When you call RenderPartial, the engine will simply pass the parent view model to the partial view, which, in your case, is expecting not a Person object, but rather a RegisterModels object.

So you have some options. I think this is probably the easiest fix for you: Create a new view model

public class PersonRegister
{
   public Person Person {get; set;}
   public RegisterModels Register {get; set;}
}

Now strongly type your view to this model

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.PersonRegister>" %> 

And call the partial like so

<%Html.RenderPartial("RegisterControl", Model.RegisterModels); %>
Forty-Two
  • 7,535
  • 2
  • 37
  • 54