Добрый вечер!Я переписываю некоторые функции следующим образом:
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));
}