Trying to use a parameter obtained from Index() co

2019-09-05 04:42发布

A bit of background. I'm working with MVC and I've appended an ID to my path so that when I pass the ID to my controller, the controller will look through a database and look for another ID that is in the same row as the ID I just passed in.

I then redirect to my Index() controller with these two IDs now present in the query string and I return the view.

My problem is that I want to that I want to link up the the second ID that I found in my Index to another controller that is associated with the Kendo UI's kendo grid create operation. I'm not quite sure how to go about this.

Don't hesitate to ask me for more details. Thanks.

Example urls: localhost/Customs/Invoicered?bcID=7SJF82NF-VFDF-83NN-SD3V-92HFN7FH4NRM

localhost/Customs/Invoice??bcID=7SJF82NF-VFDF-83NN-SD3V-92HFN7FH4NRM&trx=DSF83JFN-SDFM-32FS-8DJS-SDK36DK3332M

EDIT: Go to this link for the way I solved it. Passing data in view model to controller via kendo grid

1条回答
▲ chillily
2楼-- · 2019-09-05 05:15

I would return the 2 IDs in a ViewModel, then in the View, add the ID to the configuration of the grid's Read action:

Controller:

public ActionResult Index(int id1, int id2)
{
    return View(new MyViewModel()
    {
        ID1 = id2,
        ID2 = id2
    }
}

View:

@model MyViewModel

@Html.Kendo().Grid<MyGridViewModel>()
    ...Other Grid setup...
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Grid_Read", "MyController")
            .Data(new { id2 = @Model.ID2 })
        )
        ...Other DataSource setup
    )
)

And then have your read action on the server take an "id2" parameter.

public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request, int id2)
{
    // Do whatever you need with id2...
}
查看更多
登录 后发表回答