I do a lot of coding in jQuery for my project, but I need help with obtaining parameter names genereated by Helper with For suffix.
When I do:
Html.TextBoxFor(model => model.SomeTextParameter)
in pure html there’s generated id: “SomeTextParameter”. I’d like to get its id automagically generated in every place I use it in jQuery. How to do that?
Or, I can always manualy specify it’s name by using helper without “For”:
Html.TextBox("SomeTextParameter", this.Model.SomeTextParameter)
In this case I can control ids with easy but when I want to use Data Annotations for labels then I find another problem with connecting [Display(Name = "Really important text parameter")] with
Html.Label("SomeTextParameterLabel", <what to enter here?>).
When I use:
Html.LabelFor(model => model.SomeTextParameter)
it binds to display name so it’s displayed just as I want.
Any ideas how to solve 1st or 2nd problem?
You can write your own helper to get generated ids. This should be useful https://stackoverflow.com/a/5419261/472126
After that, you should be able to get generated Id by using this