Multiple instances of partialView

Hi,

I am using MVC 5 with VS2013. I have created a PartialView that contains certain labels and some javascript that will set the values in those labels. Now I have a question that in my view page I have two div sections and in both the divs I have to show the
same PartialView but with different data.

I can definitely place a partialView more than once but how I should differentiate between the partial view. How to set the data in both the instances differently? Do I get any instanceID or something like that.

Another thing is I will be getting that data from the database which I have to set into the javascript variables of the partialView. So what should be the better approach for that? Should I have a separate model for partialView and from that modal I should
pass the data to the partialView and javascript variables.? What should be the better approach.

Regards,
Girish

girish.nehte

I have to show the same PartialView but with different data.

that means you have 2 diffferent data – let’s say Data1 and Data2

@Html.RenderPartial("My_Partial_View" , Data1)

@Html.RenderPartial("My_Partial_View" , Data2)

Data1 and Data2 in 

@Html.RenderPartial("My_Partial_View" , Data1) line is model right?

passing diferent models with renderpartial.

Now next question comes how can I have two instances of same model with different data in a view page?

Regards,
Girish

girish.nehte

how can I have two instances of same model with different data in a view page?

I think it’s not possible. You could declare a var with the same type than the model and assing its value:

@ModelType MOD_EditCreateUser

@Code
    Dim model2 As MOD_EditCreateUser = Model
End Code

Leave a Reply