Kevin
Kevin

Reputation:

why my ASP.NET MVC Htmlhelper htmlAttributes cant work?

When I user this targ on a page like:

@Html.TextBoxFor(model => model.JobName, new { @class = "form-control" })

It can work, But when I use like this:

@Html.TextBoxFor(model => model.JobName, new { @data-provide="typeahead", })

then it can't work, because this attribute: data-provide, it have a symbol which is '-', how I can solve this problem?

Upvotes: 0

Views: 32

Answers (1)

Brad Christie
Brad Christie

Reputation: 101614

Use @data_provide. This falls under C# nomenclature, so you have to work with what is allowed (within the language confines).

MVC builds in a work-around allowing you to supplement hyphens with underscores (which will be replaced when built as HTML).

This is the same reason you must use @class over simply class (keyword collision).

Upvotes: 2

Related Questions