Search code examples
asp.net-mvcrazormaterializehtml-helper

How to configure Checkboxes Materialize Css in Web application Asp.Net MVC


How do I configure Checkboxes in Asp.Net MVC Razor.

Since in the documentation we have the following configuration Materialize for checkboxes :

<p>
   <label>
     <input type = "checkbox" />
     <span> Network </span>
   </label>
</p>

And in Razor I could not perform this configuration.

<div class = "input-field col s12">
        @Html.EditorFor (model => model.AnnualDestaque)
        @Html.LabelFor (model => model.AnnualDestaque)
        @Html.ValidationMessageFor (model => model.AnnualDestaque, "", new {@class = "text-danger"})
</div>

Solution

  • Please include model Name in your cshtml page

    @model WebApplication3.Models.Test
    @{
     ViewBag.Title = "Home Page";
     }
    
    
    @using (Html.BeginForm("Save", "Home", FormMethod.Post))
     {
      <div class="row">
      <div class="col-md-4">
        @Html.TextBoxFor(m => m.EmployeeName)
        @Html.CheckBoxFor(m=>m.IsSelected)
    
      </div>
    
       <input type="submit" value="Save" />
    
      </div>
    }
    

    Model

    public class Test
    {
        public string EmployeeName { get; set; }
        public bool IsSelected { get; set; }
    }