ASP.NET MVC CheckBoxList from model with List Property

前端 未结 4 1449
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 07:01

Apologies if the title is unclear.

I\'m trying to return my model from a form submit in ASP.NET MVC.

My question is nearly the same as this question, only di

4条回答
  •  执笔经年
    2020-12-08 07:46

    See below code, this way you don't need to hide the role Id, also when you save the selected roles for the user, you don't need to loop through all roles to see which role is selected.

    View

    @foreach (Roles info in Model.UserRoles)
    {
        
            
            
        
    }
    

    Action

    [HttpPost]
    public ActionResult CreateUsers(Model model, string[] selectedRoles)
    {
           //
    }
    

提交回复
热议问题