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
645
TextEditorFor Incorrect ID generated for nested model, uses "." in JS and "_" in HTML
posted

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 Children
  • 2671
    Offline posted in reply to Sam Elliott

    Hello,

    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:

           @(Html.Infragistics()

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

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

                  .Render())

           // 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.

    Regards,

    Damyan Petev

    Software Developer

    Infragistics, Inc.