views:

67

answers:

2

Hi

Say I have just a normal view(not strongly typed) and in this view I have this

 <% Html.RenderPartial("ViewUserControl1") %>

However this Partial View is strongly typed with a class(lets call it class1).

How do I pass data to this strongly typed view? Like in my partial view I can't go right now and do something like this

<% Model.SomeProperty %>

It would just crash. So I need to pass class1 somehow to this strongly typed view and preferably keep the view non typed.

A: 

If you can't make your parent view strongly typed, you could just add the model for your partial view to the viewdata dictionary, and pass it to the partial view, like so:

<% Html.RenderPartial("ViewUserControl1", ViewData["MyDataObject"] %>
jeroenh
+1  A: 
 <% Html.RenderPartial("ViewUserControl1", class1object) %>

or if you are using ViewData["something"] in non typed view to hold that class1 you can cast it to class1

<% Html.RenderPartial("ViewUserControl1",(class1)ViewData["something"] %>

just like that

Alexander Taran