晚上好!我用这种方式重写了某些函数:
public static MvcHtmlString DropDownList(this AjaxHelper html,
string action,
AjaxOptions options,
IEnumerable<SelectListItem> selectItems,
IDictionary<string, object> listHtmlAttributes)
但我不能用HtmlAttributes 编写工作代码。这是我的变种:
@Ajax.DropDownList("ApplSort", new AjaxOptions() {
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target",
LoadingElementId = "AjaxSearch" },
new[]
{
new SelectListItem { Value = "0", Text = "Заявки от новых к старым" },
new SelectListItem { Value = "1", Text = "Заявки от старых к новым" }
},
new IDictionary<string, object> { id = "DropDownListSort", @class = "chosen" }
)
或
@Ajax.DropDownList("ApplSort", new AjaxOptions() {
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target",
LoadingElementId = "AjaxSearch" },
new[]
{
new SelectListItem { Value = "0", Text = "Заявки от новых к старым" },
new SelectListItem { Value = "1", Text = "Заявки от старых к новым" }
},
new { id = "DropDownListSort", @class = "chosen" }
)
如何正确书写?
问题解决了。写了两个扩展,并且成功了:
public static MvcHtmlString DropDownList(this AjaxHelper html, string action, RouteValueDictionary routeValues, AjaxOptions options, IEnumerable<SelectListItem> selectItems, object htmlAttributes)
{
return DropDownList(html, action, routeValues, options, selectItems, new RouteValueDictionary(htmlAttributes));
}
public static MvcHtmlString DropDownList(this AjaxHelper html, string action, AjaxOptions options, IEnumerable<SelectListItem> selectItems, object htmlAttributes)
{
return DropDownList(html, action, options, selectItems, new RouteValueDictionary(htmlAttributes));
}