15

The Html.TextBox syntax is:

public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, 
       object value, object htmlAttributes);

So, i put my data attribute in htmlAttributes. I have tried

@Html.TextBox("date",Model.Date,new { data-myid="aaa"})

but that doesn't work for me.

2 Answers 2

29

Try using underscore _ character.

@Html.TextBox("date",Model.Date,new { data_myid="aaa"})

The runtime will convert that to data-myid

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Even if you add data_my_id_attribute it will convert the whole to data-my-id-attribute!
1

For a friendlier syntax, you could try: http://buildmvc.codeplex.com/

@Html.BuildTextBox("date", Model.Date).Data("myid", "aaa")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.