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

Redirect to another page after update in Kendo grid with inline edit

5 Answers 997 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PAUL
Top achievements
Rank 1
PAUL asked on 11 Oct 2012, 11:25 AM
I have a Kendo grid with inline editing. It works great. An issue I have right now is that after an inline update of a record, if certain conditions of the update exist I need to redirect to another Page i.e. RedirectToAction. So the code looks like:

public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, OrderViewModel order)
{           
   if (order != null && ModelState.IsValid)
   {
       order = UpdateOrder(order);
       repository.UpdateOrder(order);
  
}
   if (order.orderStatus == "HD")
         return RedirectToAction("Info");           
    return Json(ModelState.ToDataSourceResult());
 }

This code works as designed but will not display the page. This of course is due to the AJAX call which is returning to the datasource.

Several things happen on the line order = UpdateOrder(order);  This method is in the Controller and sets several fields in the record that was updated including the orderStatus. The repository.UpdateOrder(order) happens in the SessionOrderRepository class.

Since the fields in the UpdateOrder method of the Controller are not set by the user, the information is not updated in the grid either (grid updates immediately). And if for some reason the orderStatus is placed in the "HD" (hold) state we want to redirect the user to a page that displays the reason(s) that the order is on hold. Clicking Ok on that page would redirect them to the grid and all of the fields would be updated since it has to reload.

Technically this is probably not a Kendo issue but if anyone has a work around on this your help would be greatly appreciated.

Regards,

Paul

5 Answers, 1 is accepted

Sort by
0
Vesselin Obreshkov
Top achievements
Rank 2
answered on 11 Oct 2012, 08:35 PM
Since you're using AJAX, your best bet would be to do the redirect on the client side of things after the corresponding Edit event has been fired by the grid.
0
PAUL
Top achievements
Rank 1
answered on 11 Oct 2012, 08:42 PM
That is my only bet...the question is how? When I hit Save changes button in the kendo grid, the record is updated in the grid and the database. But how do i catch the event in javascript to do the redirect?

Like I said this really isn't a Kendo issue but a dilema I am sure many have seen. Question is were you able to solve it and if so how?

Thanks

Paul
0
Petur Subev
Telerik team
answered on 16 Oct 2012, 12:55 PM
Hi Paul,

I suggest you the following:

In the controller action if your condition ( if (order.orderStatus == "HD") )then you could add a ModelState error.
e.g.
ModelState.AddModelError("redirectNeeded", "The user needs to be redirected");

This way when the Json is returned to the client (which carries that ModelState error you added) the error event of the dataSource will be fired.
Then you can use the document.location.href to redirect the client to the needed page.
document.location.href="/test/test"


Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
PAUL
Top achievements
Rank 1
answered on 16 Oct 2012, 02:20 PM
Petur,

That was the ticket and it works great. Thank you so much for the input...

Regards,

Paul
0
Mikul
Top achievements
Rank 1
answered on 03 Nov 2012, 07:22 AM
Hello,

We are using kendo version 2012.2.710

I have register error event of datasource. My controller method code for read method is as below:

[SessionExpireFilterAttribute]
        public ActionResult Picklist_Read([DataSourceRequest] DataSourceRequest request)
        {
            if (ViewBag.SessionExpired != null && ViewBag.SessionExpired == true)
            {
                ModelState.AddModelError("redirectNeeded", "The user needs to be redirected");
                return Json(ModelState.ToDataSourceResult());
            }
            else
            {
                Tuple<IEnumerable<PicklistSamplesDTO>, int> PicklistCollection = GetPickListBySampleStatus(request, SampleStatus.New);
                DataSourceResult DataSourceResultObj = new DataSourceResult() { Data = PicklistCollection.Item1, Total = PicklistCollection.Item2 };
                return Json(DataSourceResultObj);
            }
        }

In our case, controller method return result without exception but error event will not fired.

Kindly guide us asap.

Reards,
Mikul Makadia








 

 

Tags
Grid
Asked by
PAUL
Top achievements
Rank 1
Answers by
Vesselin Obreshkov
Top achievements
Rank 2
PAUL
Top achievements
Rank 1
Petur Subev
Telerik team
Mikul
Top achievements
Rank 1
Share this question
or