How to write HTML5 data-atrribute in Razor MVC C#?


I am trying to specify HTML5 data-atrribute in my asp.net MVC razor code like below

 @Html.DropDownListFor(m => m.Industry, OnePassV3.utility.OptionList.GetIndustryListSelectList()
                           , new { @class="cs-select cs-skin-slide cs-transparent", @data-init-plugin="cs-select" })

but i am getting error as you can see below in the image.

how-to-specify-data-attribute-mvc-razor

So, how can I make it wok?


Asked by:- jaya
0
: 563 At:- 10/23/2017 11:28:56 AM
MVC C# Razor data-attribute-in-razor HTML5






1 Answers
profileImage Answered by:- Sam

You can show data-attribute in Razor C#, by simply changing dashes(-) into underscrore, so your above code will be like this

@Html.DropDownListFor(m => m.Industry, OnePassV3.utility.OptionList.GetIndustryListSelectList()
                           , new { @class="cs-select cs-skin-slide cs-transparent", @data_init_plugin="cs-select" })

it will work in Razor view and will be rendered as data-init-plugin="cs-select".

2
At:- 10/24/2017 7:29:40 AM
Working now :) 0
By : jaya - at :- 11/5/2017 11:52:48 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use