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

Different editortemplates when using Html helpers vs Tag Helpers

3 Answers 676 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pavlos
Top achievements
Rank 1
Pavlos asked on 14 Oct 2019, 01:34 PM

I made two identical grids.
One using the Html helper and one using the Tag helper.
Both have inline editing enabled.

However the editor templates don't seem to correspond or not even be present in some cases.
I've attached a screenshot.

How do I just make it work in both cases?

3 Answers, 1 is accepted

Sort by
0
Pavlos
Top achievements
Rank 1
answered on 14 Oct 2019, 02:02 PM
@(Html.Kendo().Grid<OrderViewModelTest>()
    .Name("TestGrid")
    .HtmlAttributes(new {})
    .Columns(columns =>
    {
        columns.Bound(c => c.OrderID).Filterable(false);
        columns.Bound(c => c.Freight);
        columns.Bound(c => c.OrderDate).Format("{0:dd/MM/yyyy}");
        columns.Bound(c => c.ShipName);
        columns.Bound(c => c.ShipCity);
        columns.Command(command => command.Edit());
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Scrollable()
    .Navigatable()
    .Sortable()
    .Filterable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(5)
        .Read(read => read.Action("Orders_Read", "Test"))
    ))
 
<div class="row">
    <div class="col-12">
        <kendo-grid name="grid">
            <columns>
                <column field="OrderID" title="Order ID">
                    <filterable enabled="false"></filterable>
                </column>
                <column field="Freight" title="Freight" />
                <column field="OrderDate" title="Order Date" format="{0:MM/dd/yyyy}" />
                <column field="ShipName" title="Ship Name" />
                <column field="ShipCity" title="Ship City" />
                <column>
                    <commands>
                        <column-command name="edit"></column-command>
                    </commands>
                </column>
            </columns>
            <scrollable enabled="true" />
            <sortable enabled="true" />
            <pageable enabled="true" />
            <editable enabled="true" mode="inline" />
            <filterable enabled="true" />
            <datasource type="DataSourceTagHelperType.Ajax" page-size="5">
                <transport>
                    <read url="@Url.Action("Orders_Read", "Test", new {Area = "Test"})"/>
                </transport>
            </datasource>
        </kendo-grid>
    </div>
</div>
1
Accepted
Alex Hajigeorgieva
Telerik team
answered on 17 Oct 2019, 09:43 AM

Hi, Pavlos,

Thank you very much for the explanations and screenshots.

The reason for the behaviour is that the model properties of the Razor syntax generated grid are inferred from the model in its definition while the TagHelper requires us to describe the data types of the properties. Once you do that, the same editor will be generated for the TagHelper grid as well:

https://docs.telerik.com/aspnet-core/tag-helpers/data-management/grid/editing

<datasource type="DataSourceTagHelperType.Ajax" page-size="5">
        <transport>
            <read url="@Url.Action("Orders_Read", "Test", new {Area = "Test"})"/>
        </transport>
        <schema  >
            <model id="OrderID">
                <fields>
                    <field name="Freight" type="number"></field>
                    <field name="OrderDate" type="date"></field>
                    <field name="UnitsInStock" type="number"></field>
                </fields>
            </model>
        </schema>
</datasource>

Give this a try and let me know in case you need further assistance.

Kind Regards,
Alex Hajigeorgieva
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.
0
Pavlos
Top achievements
Rank 1
answered on 18 Oct 2019, 10:42 AM

Good to know, must have missed that in the documentation.
Got it working perfectly now.

Thanks Alex!

Tags
Grid
Asked by
Pavlos
Top achievements
Rank 1
Answers by
Pavlos
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or