0

I am trying to implement auto complete textbox using MVC 4 Razor View. so i need to include include on attribute(data-otf-autocomplete) to the HTML.EditorFor control but it is showing error not allowing to add new attribute ?

Showing Error at :

 @Html.EditorFor(model => model.Subjects.Name, new { @data-otf-autocomplete="@Url.Action('Autocomplete_Subject')" });

Note: I can not edit/ change attribute name because that attribute is generated by 3rd party which was included in DLL component.

enter image description here

2 Answers 2

1

As per Adrian Thompson Phillips suggestions I have used and Underscores instead of dashes. @Html.EditorFor was not suggest for Autocomplete Text, so I used @Html.TextBoxFor instead of @Html.EditorFor.

It Works for me!

  1. Use Underscores instead of Dashes
  2. Use @Html.TextBoxFor instead of @Html.EditorFor

    @Html.TextBoxFor(model => model.Subjects.Name, new { @data_otf_autocomplete = @Url.Action("Autocomplete_Subject") });

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

Comments

0

MVC has a convention for working around this, simply use underscores instead of dashes and it will get converted back to dashes as MVC serves the page:

@Html.EditorFor(model => model.Subjects.Name, new { data_otf_autocomplete = Url.Action("Autocomplete_Subject") })

2 Comments

Adrian Thompson Phillips, data-otf-autocomplete was jquery UI plugin and it is included in DLL, I can't modify the attribute name, please let me know is there any alternate way to use dashes in MVC controls ?
That's no problem, see my answer above, although you've used underscores '_', when you look at the HTML it outputs, it'll render as data-oft-autocomplete and should work fine with your jQuery UI plugin.

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.