this is my renderparial
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<a href='<%= Url.Action("Edit", new {id=Model.ID}) %>'>
<img src="<%= Url.Content("~/img/pencil.png") %>" alt="Edit" width="16" /></a>
I basically want to call it in this way:
<% Html.RenderPartial("edit", new { ID = item.hlpb_ID }); %>
however, this gives me a runtime error 'object' does not contain a definition for 'ID'
so how do I send an on the fly created nameless object (because i guess thats what it is) to a renderpartial? like this works for Url.Action
You can only call members of an object directly when you use a strongly typed view.
If you want to pass an dynamic object to a RenderPartial your pretty much stuck using reflection or the dynamic keyword to access properties you don’t know at runtime. Doing this is an extremely bad practice. Generally you know what objects get passed to a view because you have to render them.
For more information about how to use the dynamic keyword check here:
http://weblogs.asp.net/shijuvarghese/archive/2010/02/03/asp-net-mvc-view-model-object-using-c-4-dynamic-and-expandoobject.aspx