Trying to use a parameter obtained from Index() controller and passing it into KendoGrid to retrieved items associated with the parameter(an id)

最后都变了- 提交于 2020-01-07 03:14:13

问题


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:


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...
}


来源:https://stackoverflow.com/questions/40224176/trying-to-use-a-parameter-obtained-from-index-controller-and-passing-it-into-k

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!