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

PopUp Edit Mode - Create not Sending Route Values to Controller

2 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phillip
Top achievements
Rank 1
Phillip asked on 29 Jun 2018, 02:00 PM

I'm using a grid with editable mode set to pop up. On the actions I have included a route value to be sent to the controller. This route value gets sent on each of the CRUD calls except for the create. 

Below is my Grid code with the route values for each of the actions. I really only need this value passed through for the Create and Read actions.

@(Html.Kendo().Grid(Model).Name("ApprovalProcessSteps").Columns(c =>
{
    c.Bound(e => e.ProcessStep);
    c.Bound(e => e.ProcessStepType);
    c.Bound(e => e.AndOr);
    c.Bound(e => e.GroupParentStep);
    c.Bound(e => e.UserId);
    c.Bound(e => e.RejectToStep);
    c.Bound(e => e.ReminderFrequency);
 
    c.Command(command =>
    {
        command.Edit();
        command.Destroy();
    }).Width(200);
})
      .ToolBar(toolbar => toolbar.Create().Text("Create New Step"))
      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ApprovalProcessStepPopUp"))
      .Pageable(pager => pager.AlwaysVisible(false).PageSizes(new List<object> {5, 10, 20, 100}))
      .DataSource(dataSource => dataSource
          .Ajax()
          .PageSize(20)
          .Model(model => model.Id(p => p.Id))
          .Create(update => update.Action("EditingPopup_Create", "ApprovalProcessSteps", new { approvalProcessId = ViewBag.approvalProcessId }))
          .Read(read => read.Action("EditingPopup_Read", "ApprovalProcessSteps", new { approvalProcessId = ViewBag.approvalProcessId }))
          .Update(update => update.Action("EditingPopup_Update", "ApprovalProcessSteps", new { approvalProcessId = ViewBag.approvalProcessId }))
          .Destroy(update => update.Action("EditingPopup_Destroy", "ApprovalProcessSteps", new { approvalProcessId = ViewBag.approvalProcessId })))
      )

 

Below is my controller code. The route value gets pass to all but my Create call. Can any point me in the right direction on what I might be doing wrong.

public ActionResult EditingPopup_Read([DataSourceRequest] DataSourceRequest request, int approvalProcessId)
{
    ViewBag.approvalProcessId = approvalProcessId;
    return Json(this.ReadInline(approvalProcessId).ToDataSourceResult(request));
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, ApprovalProcessStep approvalProcessStep, int approvalProcessId)
{
    if (approvalProcessStep != null && ModelState.IsValid)
    {
        this.CreateInline(approvalProcessStep, approvalProcessId);
    }
 
    return Json(new[] {approvalProcessStep}.ToDataSourceResult(request, ModelState));
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, ApprovalProcessStep approvalProcessStep)
{
    if (approvalProcessStep != null && ModelState.IsValid)
    {
        this.UpdateInline(approvalProcessStep);
    }
 
    return Json(new[] {approvalProcessStep}.ToDataSourceResult(request, ModelState));
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Destroy([DataSourceRequest] DataSourceRequest request, ApprovalProcessStep approvalProcessStep)
{
    if (approvalProcessStep != null)
    {
        this.DestroyInline(approvalProcessStep);
    }
 
    return Json(new[] {approvalProcessStep}.ToDataSourceResult(request, ModelState));
}

2 Answers, 1 is accepted

Sort by
0
Phillip
Top achievements
Rank 1
answered on 29 Jun 2018, 05:23 PM
I managed to work around this issue by using a query string parameter that was already being used by the controller. So I'm no longer blocked but I would still like to know why I'm un-able to send a route value to the controller on a create though.
0
Georgi
Telerik team
answered on 03 Jul 2018, 12:05 PM
Hello Phillip,

I have investigated the provided code and I did not notice anything that might cause an issue. However, I am not sure where the value in the ViewBag is set. 

I noticed that within the Read action method the value is populated, but the read method is called after the grid view is requested, therefore the value will not yet be available when the initialization script of the grid is generated.

Furthermore, have in mind that for each request a new Controller is created and therefore the ViewBag is different for each request.

Finally I have created a small sample where the value in the ViewBag is populated within the page itself and the additional parameter is sent as expected.

For your convenience I am attaching the sample. Please examine it and let me know what I am missing.


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Phillip
Top achievements
Rank 1
Answers by
Phillip
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or