Reputation: 13756
I tried the following but doesnt work:
<%Html.RenderPartial("userControl",new {personID=Model.ID, name="SomeName"});%>
In the usercontrol I have a hidden field in an ajax form to which I assign personID. It wont compile, the hidden id is not recognized.
Upvotes: 0
Views: 660
Reputation: 2077
I am not sure why would you want to do that, but here is how (strongly type Model is much better):
<%
ViewData["PersonID"] = Model.ID;
ViewData["Name"] = "SomeName";
Response.Write(
Html.RenderPartial("userControl"));
%>
OR
If you just do this:
<%=Html.RenderPartial("userControl")%>
and if your "userControl" is also strongly typed, it should be able to read "Model.ID"
Upvotes: 1
Reputation: 10582
You'd either have to use reflection or a helper class like RouteValueDictionary if you wanted to get the correct property from the anonymous type.
RouteValueDictionary is probably the easiest. Create an instance of it, passing the Model, and then use its index operator to query the values.
Eg:
<%
var modelDictionary = new RouteValueDictionary(Model);
%>
<input type="hidden" name="personID" value="<%= modelDictionary["personID"] %>" />
Upvotes: 1