0
我有一个问题,我形容它在这个地方How create UIHit YesNoNull?是否可以通过属性来做同样的事情?
我通过创建一个助手解决了这个问题:
public static MvcHtmlString YesNoNull(this HtmlHelper helper, string name)
{
return YesNoNull(helper, name, false);
}
public static MvcHtmlString YesNoNull(this HtmlHelper helper, string name, bool selected)
{
var builder = new StringBuilder(500);
builder.Append(string.Format("<input id='checkbox_{0}' type='checkbox' />Есть", name));
builder.Append("<script type=\"text/javascript\">$(function() {");
builder.Append(string.Format("$('#checkbox_{0}').click(function() {{", name));
builder.Append(@"var checked = $(this).attr('checked');if (checked != undefined) {");
builder.Append(string.Format("$('#{0}').show();}}", name));
builder.Append(string.Format("else {{$('#{0}').hide();}} }});", name));
builder.Append(string.Format("$('#checkbox_{0}').attr('checked', {1});", name, selected.ToString().ToLower()));
builder.Append(string.Format("var checked = $('#checkbox_{0}').attr('checked');if (checked != undefined){{ $('#{0}').show(); }}else{{$('#{0}').hide();}}", name));
builder.Append("})</script>");
return new MvcHtmlString(builder.ToString());
}
我用它这样:
@Html.YesNoNull("VenueUrl", false)
@Html.EditorFor(model => model.VenueUrl)
是有可能做同样的事情,但没有使用帮手和唯一的设计:
@Html.EditorFor(model => model.VenueUrl)
而且不知怎的,我做不到,因为我需要 – Mediator