USING ASP .Net MVC 4 , Razor View
I have a CheckBoxFor
:
<div class="editor-checkbox-field">
@Html.CheckBoxFor(model => model.Is2ndMailBody, new { @name = "secMailBody", @id = "secMailBody", @class = "secMailBody", @onclick = "disable(this.form.secMailBody)", @value = "Create Table", @text = "Create Table" })
</div>
But the CheckBox itself is showing. How can i show a text what the CheckBox for?
my model has :
public bool IsChecked { get; set; }
javascript is working fine and css also. I just want to know how i can show a text for this checkbox?
EDIT 1 :
I want the text Create Second Mail Body in the right side of the check box.
Answer 1: Just put the string right after the CheckBox like below.
<div class="checkbox">
<label>
@Html.CheckBoxFor(m => m.Is2ndMailBody) Create Second Mail Body
</label>
</div>
Answer 2: In Model,
[Display(Name = "Create Second Mail Body")]
public bool Is2ndMailBody{ get; set; }
In View
<div>
@Html.CheckBoxFor(m => m.IsChecked)
@Html.LabelFor(m => m.Is2ndMailBody)
</div>
First add filter to your model that called DisplayAttribute
[Display(Name = "Some Text")]
public bool IsChecked { get; set; }
And you can use Label for model
@Html.LabelFor(model => model.Is2ndMailBody)
You can use
@Html.DisplayNameFor
instead of
@Html.LabelFor
in Alizra's answer. This way, .label css style won't be applied to your text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With