How to use a hyphenated parameter in an HTML Helper?

1
Hello, I'm using the ASP.NET MVC Data Annotation in the C # language, but I'm not able to pass data-toggle on 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 any way to pass this parameter through Data Annotation ?

    
asked by anonymous 14.12.2017 / 14:05

1 answer

2

Change your code as below:

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

Properties like @ data-toggle should be passed with the underscore, that is @data_toggle .

    
14.12.2017 / 14:33