This is a migrated thread and some comments may be shown as answers.

Multiple TestBoxFor on one page

2 Answers 11 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Yauheni
Top achievements
Rank 1
Veteran
Yauheni asked on 27 Nov 2020, 03:18 PM

I have a page bound to model with multiple comboboxes and textboxes which like
@(Html.Kendo().ComboBoxFor(i => i.Accountant)...) and @(Html.Kendo().TextBoxFor(m => m.ZipCode)...) etc.
I also have a textbox bound to "Name" property of the model:
@(Html.Kendo().TextBoxFor(m => m.Name)...)

Also on the same page I have a grid (bound to another data) with popup editable window.
And this popup window also has a textbox bound to "Name" property (but from another model).
This particular textbox looks like simple input, not like kendo ui element.

I think, this is because I have two TextBoxFor elements, each bound to a property "Name" and so they have same id attributes ("#Name").

Is it possible to make textbox in popup window to looki like kendo element without renaming property of the model? Or is it possible to change the id of the second TextBoxFor element?

I tried to add the .Name("AnotherName") method to the second TextBoxFor element, but it doesn't work, the page doesn't load correctly. I tried to add the .Name("AnotherName") method to the first TextBoxFor element, but I received an error "You cannot override component name when bound to a model expression"

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 02 Dec 2020, 09:53 AM

Hello, Yauheni,

Using a For attribute in front of the component generates a name for the element, and indeed the .Name configuration cannot be set. You can try setting a different id through the HtmlAttributes configuration:

.HtmlAttributes(new { id= "newId" })

The other option would be to use another naming to avoid having two Models with the same field, as that would also avoid further confusions.

Let me know if you have any further questions.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Yauheni
Top achievements
Rank 1
Veteran
answered on 02 Dec 2020, 09:58 AM
Hello, Martin
Thank you for the answer

I resolved my problem using TextBox With .Name("AnotherName") and .Value(Model.Name) methods instead of using TextBoxFor for the "Name" property of the model.
Tags
TextBox
Asked by
Yauheni
Top achievements
Rank 1
Veteran
Answers by
Martin
Telerik team
Yauheni
Top achievements
Rank 1
Veteran
Share this question
or