Skip to content Skip to sidebar Skip to footer

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 :

Solution 1:

Please include model Name in your cshtml page

@modelWebApplication3.Models.Test
@{
 ViewBag.Title = "Home Page";
 }


@using (Html.BeginForm("Save", "Home", FormMethod.Post))
 {
  <divclass="row"><divclass="col-md-4">
    @Html.TextBoxFor(m => m.EmployeeName)
    @Html.CheckBoxFor(m=>m.IsSelected)

  </div><inputtype="submit"value="Save" /></div>
}

Model

publicclassTest
{
    publicstring EmployeeName { get; set; }
    publicbool IsSelected { get; set; }
}

Solution 2:

If you just want to have a checkbox binded with your model like that :

publicclassNetwork
{
    publicbool Selected { get; set; }
    publicstring Name { get; set; }
}

Just use :

@Html.CheckBoxFor(m=>m.Selected)
@Html.LabelFor(m=>m.Name)

Solution 3:

I was able to solve it, and I am passing the answer.

I used Html HelperDocumentation Html Helper MVC

It worked perfectly without mistakes the way it's meant to be.

<div class="input-field col s12">
    <label>
        <input data-val="true"
                data-val-required="The Advertisement field is required."id="Advertisement"/**** m => m.Advertisement ****/
                name="Advertisement"/**** m => m.Advertisement ****/
                type="checkbox"
                value="true" />

        <span>Anuncio Destaque</span>

        <input name="Advertisement"type="hidden" value="false" />
    </label>
</div>

Solution 4:

You can make it work doing this:

<label>
<input type="checkbox" name="FIELDNAME"id="FIELDNAME" value="true" class="filled-in" @(Model.FIELDNAME? "checked" : "") />
<span>@Html.DisplayNameFor(model => model.FIELDNAME)</span>
</label>
<input name="FIELDNAME"type="hidden" value="false" />

Post a Comment for "How To Configure Checkboxes Materialize Css In Web Application Asp.net Mvc"