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
  • 645
    Offline posted

    The workaround hack I've found is to modify BaseEditorRenderer<T>.Render()

    Add the line 

    id = TagBuilder.CreateSanitizedId(this._id, HtmlHelper.IdAttributeDotReplacement);

    straight after the line

    builder.Append(BuildMainElement());

    (make sure the inserted line is inside the same containing if)

    A better way, possibly, would be change BuildMainElement to return the TagBuilder rather than a string and then

    var mainElem=BuildMainElement();

    builder.Append(mainElem.ToString());

    _id = mainElem.Attributes["id"];

Reply Children