gpt4 book ai didi

asp.net - 如何创建一个用模型渲染部分 View 的助手?

转载 作者:行者123 更新时间:2023-12-02 17:09:06 29 4
gpt4 key购买 nike

我举一个非常简单的例子:

现在我必须这样写:

<% 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 };
}

最佳答案

Partial 是 RenderPartial 的 <%= 版本:

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

关于asp.net - 如何创建一个用模型渲染部分 View 的助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3720397/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com