I want to following html code using asp.net mvc 3 razor html helper:
<input type="text" .... . placeholder="Login" data-icon="user" />
I have try this one:
@Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", data-icon = "user" })
or
@Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", @data-icon = "user" })
Displayed Error:
Invalid anonymous type members declaration.
This might due to dash in data-icon not taken as attributes. How could I add data-icon attributes in text box field.
try this
Yes, you can't write like that but you can write your own Extension to solve this problem. Here is the sample code:
Or you can also use in razor like this:
Plz don't forget to mark it's right answer if it helps you :-)
This is really the same as vNext's second alternative, but if you prefer to write it in-line: