make checkbox disabled in asp.net mvc 2 and jquery

混江龙づ霸主 提交于 2019-12-14 03:05:41

问题


i got a checkbox that i would like to be disabled ? i am using asp.net mvc 2 and jquery.

<%= Html.EditorFor(p=>p.flag) %>

public class MyModel
{
  public bool flag {get;set;}
}

回答1:


you can either use jquery to disable your checkbox using

$('#flag').attr('disabled', true);

or if you want to do it on server side you have to fall back to checkboxfor helper like

<%:Html.CheckBoxFor(x => x.flag, new { disabled = "disabled" }) %>

or you can write your own editor template that can consume additionalViewData parameter of Html.EditorFor



来源:https://stackoverflow.com/questions/6590663/make-checkbox-disabled-in-asp-net-mvc-2-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!