How to set a CheckBox by default Checked in ASP.Net MVC

后端 未结 7 1437
北荒
北荒 2020-11-28 11:36

I am using CheckBox in my ASP.Net MVC project,

i want to set checkBox by default checked,

My CheckBox is

@Html.CheckBoxFor(model => model.         


        
7条回答
  •  被撕碎了的回忆
    2020-11-28 12:30

    I use viewbag with the same variable name in the Controller. E.g if the variable is called "IsActive" and I want this to default to true on the "Create" form, on the Create Action I set the value ViewBag.IsActive = true;

    public ActionResult Create()
    {
        ViewBag.IsActive = true;
        return View();
    }
    

提交回复
热议问题