【发布时间】:2009-03-25 23:36:12
【问题描述】:
在编写 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))
}
显然是一个捷径,但它是一个混蛋还是可以这样做?
【问题讨论】: