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

Taghelpers behavior different than razor syntax?

1 Answer 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Miechko
Top achievements
Rank 1
Miechko asked on 09 Oct 2018, 05:44 PM

i'm trying to figure out how to use tag helpers with grid to achieve the same functionalities as basic razor syntax. Some thing i have noticed that behave differently :  data annotations are not being used, neither for Display names nor display format, i also do not have the option to autogenerate column with tag helpers.

Here is the code in my .cshtml page

@(Html.Kendo().Grid<DemandeNonTraiteViewModel>()
        .Name("Nontraite")
        .Columns(cols =>
        {
            cols.Bound(c => c.Date);
            cols.Bound(c => c.NomComplet);
            cols.Bound(c => c.NomOrganisation);
            cols.Bound(c => c.DemandePAA);
            cols.Bound(c => c.DemandeFDT);
            cols.Bound(c => c.DemandeOrg);
        })
        .DataSource(ds => ds
            .Ajax()
            .Model(m => m.Id(p => p.Id))
            .Read(r => r.Action("DemandeNonTraite_Read", "Demande", new { Area = "Identity" }))))
 
<kendo-grid name="grid">
    <columns>
        <column field="Date" />
        <column field="NomComplet" />
        <column field="NomOrganisation" />
        <column field="DemandePAA" />
        <column field="DemandeFDT" />
        <column field="DemandeOrg" />
    </columns>
    <datasource type="DataSourceTagHelperType.Ajax">
        <schema>
            <model id="Id">
            </model>
        </schema>
        <transport>
            <read url="@Url.Action("DemandeNonTraite_Read","Demande", new { Area = "Identity"})" />
        </transport>
    </datasource>
</kendo-grid>

 

Here is my viewmodel: 

 

public class DemandeNonTraiteViewModel
 {
     public Guid Id { get; set; }
     [Display(Name = "Date")]
     [DisplayFormat(DataFormatString = "{0:d}")]
     public DateTime Date { get; set; }
     public string Prenom { get; set; }
     public string Nom { get; set; }
     public string NomOrganisation { get; set; }
 
     [Display(Name = "PAA")]
     public bool DemandePAA { get; set; }
     [Display(Name = "FDT")]
     public bool DemandeFDT { get; set; }
     [Display(Name = "Ajout organisation")]
     public bool DemandeOrg { get; set; }
 
     [Display(Name = "Nom complet")]
     public string NomComplet
     {
         get
         {
             return $"{Prenom} {Nom}";
         }
     }
 }

 

And attached are the grid that are rendered . i would love to have both render with same way as the first so that i can use taghelpers instead of razor syntax

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 12 Oct 2018, 10:59 AM
Hi Miechko,

The described behavior is expected. When using standard Razor configuration, the fluent api for the configuration are some generic type extension methods. Therefore when we create the initialization script we have access to the type of the model (Html.Kendo.Grid<TYPE>). However, when using tag helpers, we do not have access to the model as the configuration is basically a string. This is a limitation of the tag helpers and as a workaround I can suggest you to manually set the title and the format.

Furthermore, if you omit the columns configuration the grid will create a column for each field of the response object from the server.
 


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Miechko
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or