Issue
I want to use @Html.Partial("_partialView")
to include a partial view on my page in MVC 3.
Both the page and the viewmodel have a viewmodel; thus, the following error is generated:
The model item passed into the dictionary is of type '[...]page', but this dictionary requires a model item of type '[...]partialview'.
How can I use the @Html.Partial()
method while keeping the two viewmodels?
Solution
You should use this overload that allows the model object to be passed to partial view
public static MvcHtmlString Partial(
this HtmlHelper htmlHelper,
string partialViewName,
Object model
)
By the way, do you really need to call Partial
? RenderPartial
is better - it writes directly to the response stream(compared to partial that returns string), so reserves the memory. Partial views can be quite big, so there's memory overhead with Partial
if you do not absolutely need it.
Answered By - archil Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.