How do I set a checkbox in razor view?

后端 未结 10 2122
南笙
南笙 2020-12-05 17:01

I need to check a checkbox by default:

I tried all of these, nothing is checking my checkbox -

@Html.CheckBoxFor(m => m.AllowRating, new { @value          


        
10条回答
  •  情话喂你
    2020-12-05 17:47

    only option is to set the value in the controller, If your view is Create then in the controller action add the empty model, and set the value like,

    Public ActionResult Create()
    {
    UserRating ur = new UserRating();
    ur.AllowRating = true;
    return View(ur);
    } 
    

提交回复
热议问题