44

How can translate that line using TextBoxFor (MVC):

<input id="Name" name="Name" type="text" data-bind="value: Name" class="title width-7" />

Thanks

2 Answers 2

92

MVC 3 will translate underscores in html attribute names into hyphens, so something like this should do the trick

@Html.TextBoxFor(m => m.Name, new { data_bind="value: Name", @class = "title width-7" })
Sign up to request clarification or add additional context in comments.

2 Comments

How about a space? Eg: data mask ?
Spance cannot be in html attribute name. html.spec.whatwg.org/multipage/syntax.html#attributes-2
13

For example,

if you want to add data-mask

@Html.TextBoxFor(m => m.BirthDate, new { @class = "form-control", data_mask = "date" })

it will generate in html

data-mask="date"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.