1

I am trying to pass extra attribute 'data_id 'in @HTML.TextBoxFor... but I am getting no result

what I am missing in following code...

  @Html.TextBoxFor(model => model._MarkScheme.MarkSchemeId, new { id = "_MarkSchemeId_Input", @class = "ElementMarkingSchemeTitle k1-grid-input k-textbox_3", data_id =  @item.ElementID + "EMST"}) 

Many Thanks

4
  • By "no result" you mean there is no such attribute in the final HTML? Commented Mar 21, 2014 at 12:11
  • correct i can't see any data_id attribute in <input>... Commented Mar 21, 2014 at 12:12
  • Are you expecting to see data_id or data-id? Do you see other attributes? Commented Mar 21, 2014 at 12:13
  • Do you get an exception? Commented Mar 21, 2014 at 12:18

2 Answers 2

3

Underscores aren't valid in HTML attribute names so Razor converts it to a hyphen. This will render with a data-id attribute.

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

Comments

2

HTML 5 data-* attributes are expected to be data_* in ASP.Net MVC view engine to render it.

HTML syntax

<input type="text" data-my-id="5" value="something" />

MVC syntax

@Html.TextBoxFor(model => model.Name, new {[email protected]})

Your case it is data-id

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.