-1

I am trying to receive a model in my PartialView that is within the model of the parent view, it is complicated to explain, I will try to do it with a bit of code

Model A

public class example
{
string var1;
string var2;
}

And i have another model who has example as property

Model B

public class padre
{
string another_var;
example ejemplo;
}

I'm having issues when i want to recive example from a padre view

View

@model padre
<div>@Html.Partial(_PartialViewExample, Model.ejemplo)</div>

PartialView

@model example
@* some coding *@

Thats what i'm trying, but i'm getting a

System.InvalidOperationException

that tells me that the PartialView expects a example model and I'm sending it a padre model

Is the problem understood?

Thanks so much, and sry about my horrible english!

Juan Salvador Portugal
  • 1,233
  • 4
  • 20
  • 38

1 Answers1

1

Check if your ejemplo property is not null. If you're passing null into Html.Partial, MVC will think that you pass object of padre class. In this case you can write something like @Html.Partial("_PartialViewExample", (example)Model.ejemplo) of course.

P.S. Please don't name classes starting from lowercase letter. There are some naming conventions in C# that developers should respect ;)

Serega
  • 630
  • 1
  • 4
  • 12