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

6 posts, 0 answers
  1. PAUL
    PAUL avatar
    36 posts
    Member since:
    Aug 2012

    Posted 11 Oct 2012 Link to this post

    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

  2. Vesselin Obreshkov
    Vesselin Obreshkov avatar
    81 posts
    Member since:
    Jan 2010

    Posted 11 Oct 2012 Link to this post

    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. PAUL
    PAUL avatar
    36 posts
    Member since:
    Aug 2012

    Posted 11 Oct 2012 Link to this post

    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
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 16 Oct 2012 Link to this post

    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!
  6. PAUL
    PAUL avatar
    36 posts
    Member since:
    Aug 2012

    Posted 16 Oct 2012 Link to this post

    Petur,

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

    Regards,

    Paul
  7. Mikul
    Mikul avatar
    1 posts
    Member since:
    Nov 2012

    Posted 03 Nov 2012 Link to this post

    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








     

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready