gpt4 book ai didi

asp.net-mvc - ASP.NET MVC - 将 htmlAttributes 作为参数传递

转载 作者:行者123 更新时间:2023-12-04 17:20:30 25 4
gpt4 key购买 nike

我想将 htmlAttributes 作为参数传递给我的 HtmlHelper,类似于它在Html.ActionLink("linktext", "Home", null, new{width="100px"})如何将这个新的{width="100px"} 传递给我的方法

    public static string SelectCategoryAdminWithAllItem(this HtmlHelper htmlHelper, string name, **???**)
{ }

以及如何解析它?

谢谢

最佳答案

当对此类问题感兴趣时,请始终尝试查看资料。从 HtmlHelper.TextBox 的实现

public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes)
{
return htmlHelper.TextBox(name, value, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}

如您所见,参数类型是object,因为您不能使用匿名类型作为方法的参数,object 是一种选择。解析它时,您可以使用 HtmlHelper.AnonymousObjectToHtmlAttributes Method

关于asp.net-mvc - ASP.NET MVC - 将 htmlAttributes 作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6250624/

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