Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
TextEditorFor Incorrect ID generated for nested model, uses "." in JS and "_" in HTML

I have a model like the following

public class MyModel {

  public Customer Customer {get;set;}


public Customer {

   public string Name {get;set;}


I then create a view with the and use @Html.EditorFor(m => m.Customer)

my customer shared editor template has

@Html.EditorFor(m => m.Name)

and my string shared editor template has

@Html.Infragistics().TextEditorFor(m => m).Render()

Now when the HTML is generated the divs get created id="Customer_Name" but the javascript uses $("Customer.Name")

Parents Reply
  • 2671
    Offline posted in reply to Sam Elliott


    Just a quick update – indeed the behavior is caused by the control rendering the editor element using  TagBuilder.GenerateId . That correctly (for the most part, "." should be valid in HTML5) sanitizes the ID from "Person.Name" to "Person_Name", but the JS Model doesn't pick that change.

    You could override the rendering, but I believe I have an easier and safer alternative. This can be temporarily worked around by enforcing the expected ID MVC would generate with IdFor like so:


                  .TextEditorFor(m => m.Person.Name)

                  .ID(Html.IdFor(m => m.Person.Name).ToString())


           // or in the String template:

           .ID(Html.IdFor(m => m).ToString())

    Without any additional modifications, this will ensure the editor initializes and should work fine even after the fix is introduced.

    Again, thank you for providing this information.


    Damyan Petev

    Software Developer

    Infragistics, Inc.

No Data