Unique id to me template

4 posts, 0 answers
  1. Xavier
    Xavier avatar
    28 posts
    Member since:
    Dec 2010

    Posted 24 Feb 2015 Link to this post

    Hi,

    When i add or edit one grid and at the same time try to edit another grid, its  foreign key is not showing its template. I need to know how to get a id unique for my editor template. Now I show you the secene


    I have two views, in the first view I call to the second view

    @(Html.Kendo().TabStrip()
       .Name("service_details_tabstrip_#=ServiceID#")
       .Items(items => { items.Add().Text("Detall Residus")
       .Selected(true)
      .LoadContentFrom("Waste", "Serveis", new { id = "#=ServiceID#" });
    })
     .ToClientTemplate()


    In the second view I have next sentence:

    string serviceID = ViewBag.ServiceID.ToString();



    The grid on the second view:

    @(Html.Kendo().Grid<ServiceDetailViewModel>()
      .Name("waste_details_" + serviceID)
      .ToolBar(t =>{
       if (User.IsInRole("Modify")){
           t.Create().Text("Afegir Residu");
           t.Custom().Text("Afegir Residus Contracte").HtmlAttributes(new { id = "wasteContract_" + serviceID });
      }
    })
     .Columns(columns =>
    {
     columns.Bound(f => f.DetailID);
     columns.ForeignKey(f => f.Reference, (System.Collections.IEnumerable)ViewBag.CatalegResidus, "Value","Text").EditorTemplateName("GetWasteByServeis").Width(400);

    The template "GetWasteByServeis" needs something to be unique:

    @(Html.Kendo().DropDownList()
       .Name("Reference_@serviceID") <=== this it's not ok
       .DataTextField("Text")
       .DataValueField("Value")
       .Filter(FilterType.Contains)
       .OptionLabel("-please select-")
       .ValuePrimitive(true)
       .AutoBind(false)
       .DataSource(source =>
    {
     source.Read(read =>
        {
             read.Action("SearchWaste", "Serveis").Data("filterSearchWaste");
        }) .ServerFiltering(true);})
    )


    In this thread I find information relationed.
    http://www.telerik.com/forums/grid-foreign-key-field-sometime-shows-textbox



    Thanks in advance.


    Xavier.
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 26 Feb 2015 Link to this post

    Hi Xavier,

    You can use the Column's EditorViewData setting to pass the grid id to the EditorTemplate. Similar to the following:

    columns.ForeignKey(f => f.Reference, (System.Collections.IEnumerable)ViewBag.CatalegResidus, "Value","Text").EditorTemplateName("GetWasteByServeis").Width(400)
    .EditorViewData(new { gridid = "waste_details_" + serviceID });

    @(Html.Kendo().DropDownList()
       .Name("Reference" + ViewData["gridid"])
       .HtmlAttributes(new { data_bind="value:Reference" }) <!-- this is required in order to bind to the correct model field -->
       /*..*/
    )


    Regards,
    Rosen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Xavier
    Xavier avatar
    28 posts
    Member since:
    Dec 2010

    Posted 26 Feb 2015 in reply to Rosen Link to this post

    That's is ok.

    Thanks Rosen.
  4. Xavier
    Xavier avatar
    28 posts
    Member since:
    Dec 2010

    Posted 26 Feb 2015 in reply to Rosen Link to this post

    That's ok.

    Thanks Rosen.
Back to Top