I have some variables defined in partial view called (Partial1.ascx)
string value1 = "value1";
string value2 = "value2";
int id = 7;
Now in ASPX page view, I want to use the above values. In my normal view (aspx page) I have like this:
<%Html.RenderPartial("Partial1.ascx");%>
<%=value1 %> becomes <%=value2 %> with his id which is <%=id %>
But the compiler throws error that the value1, value2 and id is not defined.
How to use these variables ?
Have I to define a model (new one) and pass as parameter in RenderPartial function -> <%Html.RenderPartial("Partial1.ascx", NewModel);%> ?
Thank you
You have to define the
NewModelin a code block like this on the in the view:In your partial view you assign the properties in a code block like this:
Then you can access the properties on the original viewpage like this: