代码之家  ›  专栏  ›  技术社区  ›  Omu

如何创建要使用模型渲染局部视图的辅助对象?

  •  3
  • Omu  · 技术社区  · 15 年前

    现在我不得不这样写:

    <% 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 };
    }
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Kirk Woll    15 年前

    Partial是RenderPartial的<%=版本:

    public static string Hello(this HtmlHelper helper, string name)
    {
        return helper.Partial("hello", new HelloInput { Name = name } );
    }
    
    推荐文章