How to use a hyphenated parameter in an HTML Helper?

Asked

Viewed 59 times

1

Hello I’m using the Data Annotation ASP.NET MVC in C#, but I’m not getting past ASP.NET data-toggle in the helper CheckBoxFor:

@Html.CheckBoxFor(model => model.ReceberEmail, 
                           new { @class ="form-control", @data-toggle ="toggle"})

In my Model the code is as follows:

[Display(Name = "Receber Emails ?")]
public virtual Boolean ReceberEmail { get; set; }

Would you have some way of passing that parameter through Data Annotation?

  • I already did, just change - by _ (under line) sometimes it’s some silly things that hold us in the code

  • Mark, write an answer to your question.

  • Oops, I had answered the same thing, but removed, reply there

  • @LINQ , answered here, I marked as correct, grateful.

1 answer

2


Change your code as below:

@Html.CheckBoxFor(model => model.ReceberEmail, new { @class ="form-control", @data_toggle ="toggle"})

Properties such as @data-toggle should be passed through the underscore, ie @data_toggle.

  • Thanks for the return, @Peter-Paul, I had managed here doing this rsrs after a few hours of head-breaking, grateful for the attention

Browser other questions tagged

You are not signed in. Login or sign up in order to post.