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

Grid - EditorForModel and DisplayForModel

6 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jigar
Top achievements
Rank 1
Jigar asked on 25 Sep 2010, 07:40 AM
Hi,

If I understood it correctly, when I click on Edit button in Grid ( I used PopUp edit mode), It renders the edit view using EditorForModel. And by default DisplayForModel renders the object template. This is expected and works fine. ( I have object.ascx in my editor templates)

But How can I change this behavior, for example, I want EditorForModel to render abc.ascx instead of object.ascx just like this. This is required in case, when I use multiple models in same page ( Master / Details Grid View ).

I hope I explained it correctly.  Any suggestion How can I do this?

Thanks,

Thanks.

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 Sep 2010, 07:35 AM
Hello Jigar,

 Both your suggestions are correct. The grid is using EditorForModel when showing the popup window. To customized what get's rendered you should create an editor template for your object. There is a very nice blog post by Brad Wilson that shows how to do that.

Greetings,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jigar
Top achievements
Rank 1
answered on 27 Sep 2010, 08:17 AM
Hi Atanas,

Many thanks for your inputs.

Yes, You are right, I can customize my view by having my own object.ascx in editor template. Indeed Brad's post was really helpful. But as we know by default EditorForModel and DisplayForModel are going to render object.ascx; this is what I want to change.

For example, I want EditorForModel and DisplayForModel to render MyObject.ascx instead of Object.ascx.

Scenario: I have Master / Details grid, Let's say State and City now for State grid (for Add New and Edit)I want to render object.ascx ( which is supported by default ) but for City grid ( for Add New and Edit ) I want EditorForModel to render myobject.ascx instead of object.ascx.

How can I do this? I hope I explained it clearly.

Thanks

Jigar.
0
Atanas Korchev
Telerik team
answered on 27 Sep 2010, 08:30 AM
Hi Jigar,

You can name the editor template control after your object type - e.g. Product.ascx. ASP.NET MVC would pick it up when doing EditorForModel.

Regarr,

Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jigar
Top achievements
Rank 1
answered on 27 Sep 2010, 08:36 AM
to make above post more clear;

We can pass template name in EditorForModel and DisplayForModel
For Example:
Html.EditorForModel("MyObject")

Now, how can I pass "MyObject" to Grid's EditorForModel Method?

Thanks in Advance.

Jigar.

0
Atanas Korchev
Telerik team
answered on 27 Sep 2010, 08:37 AM
Hi Jigar,

 This is not supported. Just name the template as the type of your object.

Greetings,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jigar
Top achievements
Rank 1
answered on 27 Sep 2010, 08:37 AM
Hi Atanas,

Thanks a lot. Will give it a try.

Regards,

Jigar.
Tags
Grid
Asked by
Jigar
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jigar
Top achievements
Rank 1
Share this question
or