pass a different model to the partial view

后端 未结 3 1573
忘掉有多难
忘掉有多难 2021-01-01 15:24

I am trying to pass a different model to the partial view from a view. I have two separate controller actions for both of them and two different view models. But when I call

3条回答
  •  情话喂你
    2021-01-01 15:50

    This is quite simple to do. There is a html directive which can render a partial view. Following is the code sample:

     @Html.Partial("nameOfPartial", Model)
    

    Now here Model could be from your main controller.

    or you can define a new controller action with partialviewresult as return type and try to render it in the page like this:

    @{Html.RenderAction("Someaction", "somecontroller");}
    

提交回复
热议问题