PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] How to use @Html.Partial() directly on a page in MVC 3

 May 18, 2022     asp.net-mvc-3, partial, partial-views     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing