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

Need to send column bounded context to html partial

3 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
subbarao
Top achievements
Rank 1
subbarao asked on 23 Nov 2017, 11:07 AM

Hi,

I am trying to use editor template in grid and for that i have html partial view but i am unable to find the way to send the bounded context to my partial view. can you please help guys ??

 

 

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 27 Nov 2017, 07:44 AM
Hello,

Please examine the article below that describes in detail how you can specify a custom editor template for the Grid. 


Furthermore the example below shows the approach in action. The custom editor is defined for the Category field. 



Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
subbarao
Top achievements
Rank 1
answered on 27 Nov 2017, 10:49 AM

Hi Viktor,

Thanks for responding.

in the above two links it states that we have load the data seprately in to partila view like passing data through to viewdata. But if it is dynamic and if it is get data from server when ever i edit the coulmn it every time makes request it is not needed in my case.

In my case the one of model property will hold the collection data if i get the context of model i can pass that model directly.

Example :

@foreach (var item in Model) { <tr> @Html.Partial("_StudentItem",item) </tr> this is how done by pure asp.net MVC

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>().Name("grid").Columns(columns =>{ columns.Bound(p => p.ProductName); columns.Bound(p => p.Category).ClientTemplate(Html.Partial("Name",p)).Width(180); columns.Bound(p => p.UnitPrice).Width(130); columns.Command(command => command.Destroy()).Width(150);}) in second case i am getting context column is it poosible to get this context send to partial view.

is this possible ??

Can you please suggest if i am thinking wrong

 

 

 

0
Viktor Tachev
Telerik team
answered on 29 Nov 2017, 09:20 AM
Hi Subbarao,

The string that is passed to ClientTemplate() is serialized directly on the client. This specifies what will be displayed in the Grid cell in preview mode. Thus, adding Html.Partial there will not work. 

If you would like to display the Name property of Category I would suggest using the following approach:


columns.Bound(p => p.Category).ClientTemplate("#=Category.Name#");


As for the custom editor - it should be defined in a partial View that is in the ~/Views/EditorTemplates folder. The contents of the partial view would be similar to the following:


@model Kendo.Mvc.Examples.Models.CategoryViewModel
 
@(Html.Kendo().DropDownListFor(m => m)
        .DataValueField("CategoryID")
        .DataTextField("Name")
        .BindTo((System.Collections.IEnumerable)ViewData["categories"])
)


The name of the partial view should match exactly the sting that is passed to UIHint attribute to the Category field in ProductViewModel. For example, the above partial view will be named ClientCategory.cshtml. And the Category field definition will look similar to this:


[UIHint("ClientCategory")]
public CategoryViewModel Category
{
    get;
    set;
}


Using this approach you would be able to specify a custom editor for a field in the Grid.


Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
subbarao
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
subbarao
Top achievements
Rank 1
Share this question
or