Need to send column bounded context to html partial

4 posts, 0 answers
  1. subbarao
    subbarao avatar
    2 posts
    Member since:
    Nov 2017

    Posted 23 Nov Link to this post

    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 ??

     

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1799 posts

    Posted 27 Nov Link to this post

    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.
  3. subbarao
    subbarao avatar
    2 posts
    Member since:
    Nov 2017

    Posted 27 Nov Link to this post

    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

     

     

     

  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1799 posts

    Posted 29 Nov Link to this post

    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.
Back to Top