adding "name" attribute to CheckBoxFor

Viewed 32390

I am trying to add a "name" attribute to my CheckBoxFor and can't get it to work.

@Html.CheckBoxFor(
model => model.ProvidePracticalSuggestions, 
new { @name = "help_practicalSuggestions" 
                })

Any idea what I am doing wrong here?

Rendered HTML:

<div>
      <input data-val="true" data-val-required="The Provide practical suggestions for implementing change, e.g. step-by-step best practices field is required." id="ProvidePracticalSuggestions" name="ProvidePracticalSuggestions" type="checkbox" value="true" /><input name="ProvidePracticalSuggestions" type="hidden" value="false" />
       <span class="field-validation-valid" data-valmsg-for="ProvidePracticalSuggestions" data-valmsg-replace="true"></span>
       <label for="ProvidePracticalSuggestions">Provide practical suggestions for implementing change, e.g. step-by-step best practices</label>
</div>
8 Answers

First add filter to your model that called DisplayAttribute

[DisplayAttribute(Name = "Some Text")]
public bool IsChecked { get; set; }

And you can use Label for model

@Html.LabelFor(model => model.PropertyName)
Related