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

Redirect to new page on grid Save

1 Answer 1095 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 16 Jan 2013, 08:53 PM
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.  

[HttpPost]
        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.

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 18 Jan 2013, 05:14 PM
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       
    .Ajax()                
    .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;
    }
}
Regards,
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!
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or