最简单的方法是让控制器名称和动作名称为您的型号字符串。然后你可以使用actionlink的非强类型重载。事情是这样的:
<%=Html.ActionLink(Model.Action, Model.Controller, new { param1 = 1, param2 = 2 })%>
而且使用这样的:
<%Html.RenderPartial("PartialName", new PartialModel{Controller = "Person", Action = "Publications"})%>
如果要使用强类型的版本,你可以做这样的事情:
//Model for your partial view
public class PartialModel<TController> where TController : Controller
{
public Func<int, int, Expression<Action<TController>>> GetLinkAction { get; set; }
}
//Render the action link in your partial
<%=Html.ActionLink(Model.GetLinkAction(1, 2))%>
//Render the partialview in any page
<%Html.RenderPartial("PartialName", new PartialModel<PersonController> { GetLinkAction = (param1, param2) => x => x.Publications(param1, param2) })%>
你会的当然必须根据你的参数进行调整。强类型方法的好处在于方法不必具有完全相同的签名和参数名称。
非常感谢:)非常感谢! – 2010-05-07 10:51:41