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

Custom Pop Up form to Add new record, and controller action to run Stored Proc

2 Answers 405 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BRS
Top achievements
Rank 1
BRS asked on 31 Jul 2013, 02:48 AM
Hi Telerik,

I built a Kendo Grid that DataSourced from an EF model, which comes from a database view.
We're using stored procedures (mapped as Function Imports) to add/update records, so none of your existing examples to update the Model suits my purpose.

My first question is how can I build a custom pop up form for Add/Edit?

Secondly, how do I code up the Razor and Controller action to handle this Add/Edit from the pop up form?
For example:
Razor:
@(Html.Kendo().Grid<Models.Delegates>()
                            .Name("grid")
                            .DataSource(dataSource => dataSource
                                .Ajax()
                                .Read(read => read.Action("Delegates_Read", "Home", new { employeeId = Model.EmployeeId }))
                                .Create(create=> create.Action("Delegates_Create", "Home"))  // How to pass parameters for adding new record here?
                                
                            )
                            .Columns(columns =>
                            {
                                columns.Bound(delg => delg.EMPL_I).Title("Staff ID");
                                columns.Bound(delg => delg.EMPL_M).Title("Employee Name");
                                columns.Bound(delg => delg.POSN_X).Title("Position");
                                columns.Bound(delg => delg.DEPT_NODE_M).Title("Department");
                                columns.Bound(delg => delg.EFFT_D).Title("Effective from").Format("{0:dd/MM/yyyy}");
                                columns.Bound(delg => delg.EXPY_D).Title("Expiry date").Format("{0:dd/MM/yyyy}");
                                columns.Command(command => { command.Edit(); }).Width(70);
                            })
                            .ToolBar(toolbar => toolbar.Create())
                            .Editable(editable => editable.Mode(GridEditMode.PopUp))                            
                            .Pageable()
                        )

And in controller, can I do something like this or how else?
public ActionResult Delegates_Add([DataSourceRequest]DataSourceRequest request, 
            string employeeId, string delegatedEmployeeId, DateTime effectiveDate, DateTime expiryDate, string loginUser)
        {
            _db.AddUpdateDelegateRight(employeeId, delegatedEmployeeId, effectiveDate, expiryDate, null, null, null, null, loginUser);

            //How do I handle and relay back error messages from the above SP?
            //Nothing to return here, how do I get the view to just refresh the grid?
        }

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 Aug 2013, 10:51 AM
Hi,

Please check the answers of your questions below:

1) none of your existing examples to update the Model suits my purpose. - current examples are provided to be used as a baseline and cannot solve all possible cases where the widgets can be used, however you can use this examples and modify the code on the server side to achieve the desired behavior. If you have a concrete questions on the matter I would suggest to open a new support ticket / forum post with more information about what exactly you are trying to achieve. 

2) My first question is how can I build a custom pop up form for Add/Edit? - you can define the custom editor template name (filename) using the TemplateName method (more information about the Editor Templates can be found in this help article): 

//the "yourCustomTemplateName.cshtml" editor should be placed under the EditorTemplates folder
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("yourCustomTemplateName"))

Our CodeLibrary already contains example of custom PopUp editor template - you can check it here.

3) And in controller, can I do something like this or how else? - Basically you can accept the full model or given properties from the request - current setup looks valid. 

4) How do I handle and relay back error messages from the above SP? Nothing to return here, how do I get the view to just refresh the grid? -You should include the errors to the ModelState and return it to the client side where you can handle the errors using the Error event of the DataSource. We already provide such example in our CodeLibrary

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
BRS
Top achievements
Rank 1
answered on 02 Aug 2013, 07:05 AM
Hi Vladimir,

Thanks very much for your reply. In regards to the 4th point:
4) How do I handle and relay back error messages from the above SP? Nothing to return here, how do I get the view to just refresh the grid? -You should include the errors to the ModelState and return it to the client side where you can handle the errors using the Error event of the DataSource. We already provide such example in our CodeLibrary. 

The CodeLibrary link you provided points to the same API document location, anyway I managed to find it Here.
I just did a quick and dirty test and it's working fine.
Post it here in case someone else is looking for similar solution.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delegates_Revoke([DataSourceRequest]DataSourceRequest request, RPRT_DELG_FULL delegateEmployee, string loginUser)           
{
    try
    {
        _db.AddUpdateDelegateRight(null, null, null, null, null, loginUser, delegateEmployee.DELG_I, null, null);
    }
    catch (DataException dex)
    {
        ModelState.AddModelError("Data Error", dex.InnerException.Message);
    }           
 
    return Json(ModelState.ToDataSourceResult());
}

Also thanks for pointing me to the Editor Template example, I've managed to make some progress now.
Tags
Grid
Asked by
BRS
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
BRS
Top achievements
Rank 1
Share this question
or