【发布时间】:2015-02-19 15:59:56
【问题描述】:
我是 ASP.NET MVC 的新手。我继承了我正在尝试使用的代码库。我需要添加一些基本的 HTML 属性。目前,在我的 .cshtml 文件中,有这样一个块:
@Html.DropDown(model => model.SomeValue, Model.SomeList)
这引用了Extensions.cs 中的一个函数。该函数如下所示:
public static MvcHtmlString DropDown<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, IEnumerable<string> items, string classes = "form-control")
{
var attributes = new Dictionary<string, object>();
attributes.Add("class", classes);
return System.Web.Mvc.Html.SelectExtensions.DropDownListFor(html, expression, itemList.Select(x => new SelectListItem() { Text = x.ToString(), Value = x.ToString() }), null, attributes);
}
我现在有一个案例,我需要在某些情况下禁用下拉菜单。我需要评估Model.IsUnknown 的值(这是一个布尔值)以确定是否应启用下拉列表。
我的问题是,如果需要,如何禁用下拉列表?此时,我不知道是否需要更新我的 .cshtml 或扩展方法。
感谢您提供的任何指导。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 razor