2

I have a ViewModel that is used for a view. Within that view, I open up a Partial View that is used for one of the HTML tabs that I've put up.

I would like to use another ViewModel for that Partial View so at the moment I have a parent ViewModel and then have a child ViewModel.

Is it better to do it like this or have it completely separated by instead of using @Html.Partial(), I should use @Html.RenderAction?

Tieson T.
  • 20,030
  • 4
  • 69
  • 86
SamIAm
  • 1,805
  • 4
  • 22
  • 41
  • possible duplicate of [Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction](http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction) – Manik Arora May 14 '15 at 05:01
  • OP is not asking difference between two – Ehsan Sajjad May 14 '15 at 05:02
  • The answer in that question clearly answers what the OP needs to ask, also there are many more answers in that question which resolve to this same question :) – Manik Arora May 14 '15 at 05:02
  • Both render a partial view. It depends if you need to perform some logic to render the partial. If so you would use `@html.Action()` to call a `[ChildActionOnly]` method. –  May 14 '15 at 05:03
  • Note also that if the view is for editing the child view model, then you should not be using a partial but rather an EditorTemplate for the typeof child model (otherwise it will be necessary to pass a `HtmlFieldPrefix` to the partial –  May 14 '15 at 05:05

0 Answers0