【发布时间】:2011-06-23 21:14:23
【问题描述】:
我尝试将一些 htmlextensions 添加到我的 mvc 项目中。当我尝试使用它们时,他们都期待这个 HtmlHelper htmlHelper 参数?但根据所有示例,这些都不是预期的......我做错了什么?
public static string RadioButtonListFor(this HtmlHelper htmlHelper, Expression> expression, String tagBase) where TModel : class { 返回 htmlHelper.RadioButtonListFor(表达式, tagBase, null); }
public static string RadioButtonListFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, RadioButtonListViewModel>> expression, String tagBase, object htmlAttributes) where TModel : class
{
return htmlHelper.RadioButtonListFor(expression, tagBase, new RouteValueDictionary(htmlAttributes));
}
public static string RadioButtonListFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, RadioButtonListViewModel>> expression, String tagBase, IDictionary<string, object> htmlAttributes) where TModel : class
{
var inputName = tagBase;
RadioButtonListViewModel radioButtonList = GetValue(htmlHelper, expression);
if (radioButtonList == null)
return String.Empty;
if (radioButtonList.ListItems == null)
return String.Empty;
var containerTag = new TagBuilder("td");
containerTag.MergeAttribute("id", inputName + "_Container");
foreach (var item in radioButtonList.ListItems)
{
var radioButtonTag = RadioButton(htmlHelper, inputName, new SelectListItem { Text = item.Text, Selected = item.Selected, Value = item.Value.ToString() }, htmlAttributes);
containerTag.InnerHtml += radioButtonTag;
}
return containerTag.ToString();
}
【问题讨论】:
标签: asp.net-mvc-3 htmlextensions