晚上好!我重写某些功能以这样的方式
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));
}
这肯定看起来像它会工作,如果没有更好的选择,我会实现它,但我希望的东西,我可以把成HTML帮手。我编辑了这个问题来反映这一点。 – Bobson
@Bobson,你最好将我已经显示的代码外部化到[自定义jQuery插件](http://docs.jquery.com/Plugins/Authoring)中。您不需要编写HTML助手,因为它已经存在:'Html.DropDownListFor'。一旦你有了jquery插件,你只需将它附加到你的WebGrid。 –