1
votes

In my asp.net mvc3 application i have created two partial views for two different action that is, partialviewresult setcomment and partialviewresult getcomment

i have created partial view using create a strongly type view and different scaffold template for _setcomment i am using create template and for _getcomment i am using List template.

Now i want to call both _setcomment and _getcomment partial view in one view.

in my view file .cshtml

_setcomment - 
            @model <NAMESPACE>.<MODELNAME>
            <some code>
_getcomment - 
            @model IEnumerable<<NAMESPACE>.<MODELNAME>>
            <some code>

how can i call diiferent partial view in one view? any suggestions?

2

2 Answers

0
votes

There are different ways to do it.

If you already have the model class data in the Main view you can use like In the main view call

@Html.Partial("PartialViewName1",model1)
@Html.Partial("PartialViewName1",model2)

If you do not have the model class data in the mail view then you can call the action on the controller and from there return the partial view.

@Html.Action("Controller","Action1")
@Html.Action("Controller","Action2")

In the Controller class

PartialResult Action1()
{
 model = new ModelClass();
 return PartialView(model);
}

Hope this helps.

0
votes

The answer to your question is to use the following within a single view:

@{ Html.RenderAction("ActionName", "ControlerName"); }
@{ Html.RenderAction("ActionName2", "ControlerName2"); }

This would do what you are trying to achieve, however, I think there is a problem with design. What are you trying to achieve?