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

Passing grid dataitem to another view (ASP.NET MVC).

1 Answer 379 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Navin
Top achievements
Rank 1
Navin asked on 13 Aug 2013, 10:19 PM
Hi.

I currently have the following Model:
public class AwesomeDTO
{
  public string ID {get;set;}
  public string Name {get;set;}
  public string Description {get;set;}
 
}
I currently have a following partial view with a grid.
@model IEnumerable<AwesomeDTO>
 
@(Html.Kendo().Grid(Model)
    .Name("AwesomeGrid")
    .Columns(columns =>
            {
                             
                columns.Bound(u => u.Name).Title("Name").Filterable(true).Width(200);
                columns.Bound(u => u.Description).Title("Description").Filterable(false).Width(200);
                columns.Command(command => command.Custom("Manage").Click("manageUser").Text("Manage")).Title("Manage");
            }
        )
    .Pageable()    
    .Filterable(filter => filter.Enabled(true))
    .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .PageSize(10)
            .Model(model => model.Id(u => u.ResourceID))
            .Events(events => events.Error("onError"))
                .Read(read => read.Action("GetAwesome", "Awesome"))
       )
     )

The custom command calls the following Javascript function "manageUser" defined as follows:

function manageUser(e) {
        e.preventDefault();
 
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var result;
 
        debugger;
        $.ajax({
            url: '@Url.Action("ManageAwesoem", "Awesome")',
            type: 'POST',
            data: JSON.parse(JSON.stringify(dataItem)),
            content: 'text/html',
            success: function (data) {
                alert(data);
            },
            error: function (data) {
                alert('error:' + data);
            }
        });
    }

My Controller is as follows:
public ActionResult ManageAwesome(AwesomeDTO userToManage)
{
    return View(userToManage);
}

I would like the View to render with the AwesomeDTO properties. The step where I am not quite understanding is when and how to call the ManageAwesome view so that it renders in a new location in the browser. I do not want to expose the ID of the AwesomeDTO in the URL string and so I am looking for an alternative way to achieve this from the Kendo Grid.

Any help would be appreciated.

Thanks,
Navin

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Aug 2013, 10:12 AM
Hello Navin,

 You could try using only JSON.stringify. Otherwise jQuery won't send the data in JSON format.

$.ajax({
            url: '@Url.Action("ManageAwesoem", "Awesome")',
            type: 'POST',
            data: JSON.stringify(dataItem),
            contentType: "application/json",
            success: function (data) {
                alert(data);
            },
            error: function (data) {
                alert('error:' + data);
            }
        });

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Navin
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or