Redirect to new page on grid Save

2 posts, 0 answers
  1. Rick
    Rick avatar
    21 posts
    Member since:
    Mar 2012

    Posted 16 Jan 2013 Link to this post

    I have 2 Views:  one called Index and one called Summary.  I want to be able to input the values on Index and display back the values to the user on Summary, similar to shopping cart functionality on your favorite e-commerce sites.  The code for the Index is working as expected.  Here's the code I have for my Create action result that is bound to the Save button on the grid.  

            public ActionResult Create([Bind(Prefix = "models")]List<ProductModel> products)
                if (products != null)
                    products = CalculateRoyalties(products);
                return RedirectToAction("Summary", products);
                //return View("Summary", products);

    I've tried both RedirectToAction and return View as seen in code above.  Return View will call the page but will not redirect to it.  RedirectToAction doesn't seem to do anything.  In both cases, my screen returns to my Index page instead of my Summary page.  The products is the list that I am passing to the Summary page to display.  

    Any help would be appreciated.
  2. Dimiter Madjarov
    Dimiter Madjarov avatar
    2299 posts

    Posted 18 Jan 2013 Link to this post

    Hello Rick,

    The grid is making an ajax requests, so you cannot redirect the page itself, but the ajax request. Therefore I suggest you do the redirection on the client side. First attach to the requestEnd event of the data source.

    .DataSource(dataSource => dataSource       
        .Events(events => events.RequestEnd("onRequestEnd"))

    Then in the handler, you should check the type of the request (in your case - create AND/OR update) and ensure the validity of the model. The redirection can be done with window.location.href and the data can be passed as get parameters.

    function onRequestEnd(e) {
        if ((e.type == "create" || e.type == "update") && !e.response.modelState) {
            var data = e.response.Data[0];
            var returnUrl = "@(Url.Action("Index", "Home"))" + "?product=" + data.ProductID;
            window.location.href = returnUrl;
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top