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")
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"];
Hello,
I attempted to reproduce the behavior mentioned in your previous post by setting up a page with two EditorFor referencing a model as the one in your post and did not see any ID's as the one mentioned.
I am attaching a sample I used to reproduce this behavior. Feel free to modify it and send it back if you feel this is not an accurate description of what you are trying to achieve.
Let me know if you have any questions.
Nope, that's not it, for some reason my computer didn't like updating your project - so I created a new one and provide the example.
You can see in the generated HTML that the div is Person_Name but the jquery is Person.Name
I was able to modify the sample I initially provided to reproduce the ID being set to the ClassName_Property format.
I am unsure as to what you are referring to by jquery is ClassName.Property. What issues is this causing?
I am attaching a sample I used to test this behavior.
Your sample appears to be missing the editor templates.
My sample context is supposed to generate a page that has a text box for the Customer.Person.Name, with the model for the page being customer
The problem is the generated HTML is
<div id="Person_Name"></div><script type="text/javascript">$(function () {$('#Person.Name').igTextEditor({ value: 'Testing', inputName: 'Person.Name' });});</script>
As you can see, the DIV is created with an ID of "Person_Name" but the javascript tries to apply igTextEditor to an Element with the id "Person.Name" and so nothing is rendered.
Thanks for the additional details. I was able to reproduce the behavior mentioned in your post.
I logged this within our internal tracking system with the id 221280 for further examination by our engineering staff.
Let me know if you have any further questions.
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.