Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 469.3k

How to create checkbox on asp.net mvc?

Mar 20 2020 1:41 AM
Hi team
 
I cant seem to make my checkbox to access my model fields and actionResult List that i have created.Please help me to improve my logic better, see this here below;
  1.  public ActionResult DietReq()  
  2.         {  
  3.             EditTrainingRegFormViewModel model = new EditTrainingRegFormViewModel();  
  4.   
  5.             model.Dietary_requirement = new List<CheckBox>  
  6.             {  
  7.                 new CheckBox {Text = "None"},  
  8.                 new CheckBox {Text = "Vegetarian"},  
  9.                 new CheckBox {Text = "Vegan"},  
  10.                 new CheckBox {Text = "Halaal"}  
  11.             };  
  12.   
  13.             return View(model);  
  14.         }  
  15.   
  16. // Model  
  17. public List<CheckBox> Dietary_requirement = new List<CheckBox>();  
  18.  public class CheckBox  
  19.     {  
  20.           
  21.         public string Text { getset; }  
  22.         public bool Checked { getset; }  
  23.   
  24.           
  25.     }  
  26.   
  27. // View class  
  28.   <div class="row">  
  29.                                 <label for="Dietary Requirements">Dietary Requirements</label>  
  30.                                 <div class="input-group col-md-offset-3 col-sm-6 col-xs-6">  
  31.                                     <div class="input-group pull-left">  
  32.                                                       
  33.                                         @Html.CheckBox("Vegetarian"false)  
  34.                                     </div>  
  35.                                       
  36.                                 </div>  
  37.   
  38.                             </div>  
 

Answers (2)