在编写 htmlhelper 扩展时,如果我想为我的 htmlhelper 扩展方法支持类似结构的 ctor,我使用RouteValueDictionary
如下:
public static string ListBoxDict(this HtmlHelper htmlHelper,
string name,
object value,
object htmlAttributes)
{
return ListBoxDict(htmlHelper,
name,
value,
((IDictionary<string, object>)
new RouteValueDictionary(htmlAttributes)));
}
我的问题真的是为什么需要RouteValueDictionary
......我知道你不能只是投到htmlAttributes
......IDictionary<string, object>
虽然我不确定为什么,这可能是我感到困惑的地方。不应该RouteValueDictionary
与路由有关,因此与 HtmlHelper 方法无关?就像我说的那样,我可能错过了重点,所以如果有人能告诉我我错过了什么,我会很高兴。
干杯...
编辑:响应丹的回答-->
我只是按照我在输入帮助程序的 mvc 源代码中看到的内容......
- 见“
src\SystemWebMvc\Mvc\Html\InputExtensions.cs
”
它的作用如下:
public static string TextBox(this HtmlHelper htmlHelper,
string name,
object value,
object htmlAttributes)
{
return TextBox(htmlHelper,
name,
value,
new RouteValueDictionary(htmlAttributes))
}
显然是一个捷径,但它是一个混蛋还是可以这样做?