我有一个用于自定义适配器的单选按钮列表,但是如果重置了用户表单数据,并且之前没有提交任何数据,则始终预先选择一个单选按钮(第一个),我想避免这种情况,我该如何实现?
@Html.RadioButtonForSelectList(model => model.ViewModelForThingCreate.ThingTypeID, Model.ViewModelForCarCreate.CarTypeSelectList)
和:
public static MvcHtmlString RadioButtonForSelectList<TModel, TProperty>(this HtmlHelper<TModel> HTMLHelper,Expression<Func<TModel, TProperty>> Expression, IEnumerable<SelectListItem> ListOfValues)
{
var MetaData = ModelMetadata.FromLambdaExpression(Expression, HTMLHelper.ViewData);
var SB = new StringBuilder();
if (ListOfValues != null)
{
foreach (SelectListItem Item in ListOfValues)
{
var ID = string.Format("{0}_{1}", MetaData.PropertyName, Item.Value);
var Radio = HTMLHelper.RadioButtonFor(Expression, Item.Value, new { id = ID }).ToHtmlString();
SB.AppendFormat("<label class=\"radio inline\" for=\"{0}\">{1} {2}</label>", ID, Radio, HttpUtility.HtmlEncode(Item.Text));
}
}
return MvcHtmlString.Create(SB.ToString());
}
谢谢!