我会给出一个非常简单的例子:
目前我必须这样写:
我希望能够像这样点赞:
所以我想知道如何创建这个帮助程序:
目前我必须这样写:
<% Html.RenderPartial("hello", new HelloInput { Name = "Jimmy" } ); %>
我希望能够像这样点赞:
<%=Html.Hello("Jimmy") %>
所以我想知道如何创建这个帮助程序:
public static string Hello(this HtmlHelper helper, string name)
{
return the result of rendering partial view "hello" with HelloInput{ Name = name };
}
new HelloInput { Name = "Jimmy" }
替换为new HelloInput { Name = name }
。 - davehauser