This works:
@(Html.Infragistics().HtmlEditorFor(p => p.MyHtmlText).ID("MyHtmlText").InputName("MyHtmlText").Render())
But this doesn't:
@(Html.Infragistics().HtmlEditorFor(p => p.Person.Name).ID("Person.Name").InputName("Person.Name").Render())
Is there a way to use the second approach?
Hello Luis,
It does not work because "Person.Name" is passed and accepted as string and cannot be evaluated. Please try to pass it without the quotes:
@(Html.Infragistics().HtmlEditorFor(p => p.Person.Name).ID(Person.Name).InputName(Person.Name).Render())
or maybe Model.Name. Howewer it depends on your configuration if this would work. Please explain what would you like to achieve, and what do you expect Person.Name to return ?
It would be also helpful if you provide more code from your model and controller and I will suggest accordingly.
Thanks Hristo. Your approach is not what I need because that will render a control with an Id and input name equal to the value of Person.Name, say for example that Person.Name == "Luis Enrique" then the controll will have that Id and input name, i.e. "Luis Enrique", worse: that can be a problem if Person.Name is equal to "". What I pretend is to set Id and input name literally called "Person.Name", this is not a problem with other controls. So if I have:
@(Html.Infragistics().HtmlEditorFor(p => p.Person.Name) .Height("300") .Width("100%") .ShowTextToolbar(true) .ShowInsertObjectToolbar(true) .ShowFormattingToolbar(true) .ShowCopyPasteToolbar(false) .Render())
That will produce:
<div id="Person.Name"></div><script type="text/javascript">$(function () {$('#Person.Name').igHtmlEditor({ inputName: 'Person.Name', value: '', height: '300', width: '100%', showTextToolbar: true, showInsertObjectToolbar: true, showFormattingToolbar: true, showCopyPasteToolbar: false });});</script>
But no editor is rendered to the user. For now I decided to set it like "PersonName". You would ask, why to have an Html editor for a person name? well, it is just an example, don't take it so seriously. I don't want to extend on this issue because I found a solution but it is interesting that it is not possible to name a control the way I pretended to do it: with a dot in the middle. Thanks.
Thank you for your explanation. I did not assume you wanted to literally set this string as id for the control, but now it makes sense what you are trying to do.
Please note that the reason an editor is not rendered is that the jQuery selector will not be able to find the element where to initialize:
$('#Person.Name') will return []
In this case you need to escape the dot character using slashes:
@(Html.Infragistics().HtmlEditorFor(p => p.Person.Name).ID("Person\\\\.Name").InputName("Person.Name").Render())
this will produce the following jQuery selector:
$('#Person\\.Name') which will find the element and will render the control.
Please let me know if you have further questions on the matter.
Hi Hristo! Even with that change the control is not rendered, I get this code but no editor at user interface:
<script type="text/javascript">$(function () {$('#MainProduct\\.Name').igHtmlEditor({ inputName: 'MainProduct\\.Name', value: 'Best Product', height: '200px', width: '100%', showTextToolbar: true, showInsertObjectToolbar: true, showFormattingToolbar: true, showCopyPasteToolbar: false });});</script>
Check out the attached code. I am reusing another example with categories and products and I use Name property just to test. I set inputName equals to Id but still nothing works. Any advice?
Actually that is trickier than I first thought. When you define .ID("MainProduct\\.Name") the MVC wrapper will create the following element
<div id="MainProduct\.Name"> and $('#MainProduct\\.Name') will again fail to find it. You see you will always have the same number of slashes and will not be able to escape that way.
I am going to suggest what worked for me ( I have tested my code in such scenario, it worked and this is why I initially suggested it without handling this other situations):
1) Define an html element with the desired id:
2) Define the ID in the wrapper as follows:
.ID("MainProduct\\\\.Name")
This will produce the following js code:
$(function () {$('#MainProduct\\.Name').igHtmlEditor()..............
and this selector $('#MainProduct\\.Name') will be able to find the previously defined element and will instantiate the control on it.
Hello,
I'm just following up to see if you need any further assistance with this issue. If so please let me know.