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

Unique id to me template

2 Answers 503 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 24 Feb 2015, 09:40 AM
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 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 26 Feb 2015, 08:02 AM
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.

 
0
Xavier
Top achievements
Rank 1
answered on 26 Feb 2015, 10:57 AM
That's is ok.

Thanks Rosen.
Tags
Grid
Asked by
Xavier
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Xavier
Top achievements
Rank 1
Share this question
or