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

Create different edit and create page in telerik mvc

1 Answer 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kemuel
Top achievements
Rank 1
Kemuel asked on 18 Oct 2018, 02:12 PM
im trying out Telerik and the application I am working on requires me to have a different create and edit screen. In Mvc you of course had your create and edit page and you could edit those how you like. In Telerik you don't get those, but I was made aware you could create your own edit profile
I then proceeded to do that with the following code
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("editClient"))
Good news is that you get a different page for the edit, and the bad news is that, this is also now the create page. I'm grateful for assistance in getting this done.

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 22 Oct 2018, 10:48 AM
Hello Kemuel,

Based on the provided information I assume that the requirement is to use different popup templates for editing and creating. Please correct me if I am wrong.

A possible solution is to use a Kendo Template and within it check whether the item is new and depending on that condition display the corresponding template.

e.g.
<script>
        $(function () {
            var grid = $('#grid').data('kendoGrid');
            var options = grid.options;
            options.autoBind = true;
            options.toolbar = [{ name: "create" }]
            options.editable.template = $("#template-edit").html()
            grid.setOptions(options);
    })
</script>
 
<script type="text/x-kendo-template" id="template-edit">
    #if(data.isNew()) {#
    #var createTemp = kendo.template($("\#createTemplate").html());#
    #=createTemp(data)#
    #} else {#
    #var editTemp = kendo.template($("\#editTemplate").html());#
    #=editTemp(data)#
    #}#
</script>
 
<script type="text/x-kendo-template" id="createTemplate">
    @Html.Partial("CreateTemplate")
</script>
 
<script type="text/x-kendo-template" id="editTemplate">
    @Html.Partial("EditTemplate")
</script>

Where the CreateTemplate and EditTemplate are the views for editing and creating.

For your convenience I am attaching a small sample which demonstrates the above approach.


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
Kemuel
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or