我在mvc5项目cshtml页面中实现了两个单选按钮。
点击第一个单选按钮时,它会突出显示,但在点击第二个单选按钮时永远不会取消选择。意思是两个单选按钮同时突出显示。
代码:
<div class="panel-content sublevel-2">
<div class="controls-group">
<div class="child min-w200">
@Html.KocokeRadioButtonFor(m => m.InvoiceDateType, (int)InvoiceDateType.NextScheduled, new { @cokechecked = true }, new { @id = "txtNextScheduled" })
@Html.cokeLabel(RecurringPayableResx.NextScheduled, new { @class = "" })
</div>
<div class="child">
@Html.KocokeRadioButtonFor(m => m.InvoiceDateType, (int)InvoiceDateType.Other, new { @cokechecked = false }, new { @id = "txtOther" })
@Html.cokeLabel(RecurringPayableResx.Other, new { @class = "" })
</div>
</div>
<div class="form-group">
<div class="datepicker-group">
@Html.KocokeTextBoxFor(m => m.Data.RunDate, new { @cokeDatePicker = "Data.RunDate", @cokedisable = "Data.IsOtherDateDisabled" }, new { @id = "txtOtherDate", @class = "datepicker default" })
</div>
</div>
</div>'
感谢您的帮助!!
<div class="controls-group">
<div class="child min-w200">
<span class='icon radioBox'><input data-bind="cokechecked:True" id="txtNextScheduled" name="InvoiceDateType" type="radio" value="0" /></span>
<label class="" for="">Next Scheduled</label>
</div>
<div class="child">
<span class='icon radioBox'><input data-bind="cokechecked:False" id="txtOther" name="InvoiceDateType" type="radio" value="1" /></span>
<label class="" for="">Other</label>
</div>
</div>
更新自定义类:
public static MvcHtmlString KocokeRadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression, object value, object koAttributes,
object htmlAttributes = null)
{
return RadioButtonHelperFor(htmlHelper, expression, value, koAttributes, htmlAttributes);
}
以下是上述类
调用的自定义类private static MvcHtmlString RadioButtonHelperFor<TModel, TProperty>(HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression, object value, object koAttributes = null,
object htmlAttributes = null)
{
var metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
var htmlDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
var koDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(koAttributes);
var control = CommonExtensions.CustomizedDictionary(ControlType.Radio, htmlHelper,
ExpressionHelper.GetExpressionText(expression), htmlDictionary, koDictionary, metadata);
if (koDictionary.Count > 0)
{
var databind = CommonExtensions.GetKoBindings(koDictionary);
htmlDictionary.Add("data-bind", databind);
}
return
MvcHtmlString.Create(GetSpan(control,
htmlHelper.RadioButtonFor(expression, value, htmlDictionary).ToHtmlString()));
}