Which checkbox is checked(controller) and results to list

后端 未结 2 905
感动是毒
感动是毒 2021-01-27 06:44

I am new to asp.net mvc. I am making an online video store application.

I have this view:

where users can choose which videos their gonna rent. The cod

2条回答
  •  迷失自我
    2021-01-27 07:18

    you may want to build a view model

    public class YourDBContext
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    public class YourDBContextView
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool IsSelected { get; set; }
    }
    

    and use @using (Html.BeginForm()) on the view

    [HttpPost]
    public ActionResult Index(IEnumerable obj)
    {
        //You can get your checkbox here
        foreach(YourDBContextView view in obj)
        {
            bool test = view.IsSelected;
        }
    }
    

提交回复
热议问题