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

Redirect to strongly typed view based on grid selection

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 20 Apr 2015, 09:23 PM

When a user selects a row in my grid, I can get the dataItem from a button click as follows:

$("#viewApplicationBtn").on("click", function () {
        var grid = $("#Grid").data("kendoGrid");
        var gridData = grid.dataItem(grid.select());

 

What I would like to do from this point is post this back to my controller, let the MVC model binder map to my ViewModel, and then redirect to another view which is of that model type.

The roadblock I'm facing is that an ajax post won't accomplish this and I can't pass the properties in a Url.Action helper because there are too many

here is my ajax:

$.ajax({
            type: "POST",
            url: "@Url.Action("ValidateModel")",
            datatype: "json",
            contentType: "application/json",
            data: JSON.stringify(gridData),
            success: function(data) {
                window.location.href = @Url.Action("Details", "GridController");
            },
            error: function(data) {
                console.log("post failed");
            }
        });

 

 

So how can I use my grid selection to post to another view with a Model?

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Apr 2015, 06:04 AM
Hi Andrew,

We are not sure what you mean by "ajax post won't accomplish this". What happens when the $.ajax executes? Does it hit the ValidateModel action? Is the parameter of the ValidateModel action properly populated?

Providing some sample code would allow us to give more suggestions.

Regards,
Atanas Korchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Andrew
Top achievements
Rank 1
answered on 23 Apr 2015, 02:48 PM

What I mean is that because it's an ajax post and not a "regular" form post, my MVC method for showing the grant Details view does not redirect the browser on it's return statement:

[HttpPost]
public ViewResult Details(string grantId)
{
    //Query the record based on the id
    var grantApp = _grantFormService.SelectGrantById(grantId);
 
    //Pass that model to the details view
    return View(grantApp ?? new GrantFormDTO());
}

I have since gone a different route and wrapped the grid in a Html.BeginForm and simply passed the row id back to my controller so that I can query the model from the database again and pass it to my Details view.

Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or