英文:
C# MVC application with Kendo grid - passing multiple parameters
问题
我需要从我的Kendo网格数据源发送2个参数到我的控制器。这是我的当前代码的样子:
@(Html.Kendo().Grid<OwnerViewModel>()
.Name("OwnerGrid")
.AutoBind(true)
.Columns(columns =>
{
columns.Bound(pl => pl.RecordDate).Width(20).Title("Record Date").Format("{0:MM/dd/yyyy}");
columns.Bound(pl => pl.Unit).Width(15).Title("Unit");
columns.Bound(pl => pl.Own_Name).Width(45).Title("Name");
columns.Bound(pl => pl.Own_Salutation).Width(45).Title("Salutation");
columns.Bound(pl => pl.Own_MailAddr).Width(45).Title("Mailing Addr");
columns.Bound(pl => pl.Own_City_St_Zip).Width(45).Title("City,State,Zip");
columns.Bound(pl => pl.Own_PropAddr).Width(45).Title("Property Address");
})
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => { read.Action("GetOwnerList", "Owners").Data("{ FileNum: " + @Model.FileNum + " , SecondParam: 'YourSecondValue' }"); })
)
)
这将发送名为'FileNum'的第一个参数以及名为'SecondParam'的第二个参数到Owners控制器的GetOwnerList方法中。
英文:
I need to send 2 parameters from my Kendo grid datasource to my controller. This is what my current code looks like:
@(Html.Kendo().Grid<OwnerViewModel>()
.Name("OwnerGrid")
.AutoBind(true)
.Columns(columns =>
{
columns.Bound(pl => pl.RecordDate).Width(20).Title("Record Date").Format("{0:MM/dd/yyyy}");
columns.Bound(pl => pl.Unit).Width(15).Title("Unit");
columns.Bound(pl => pl.Own_Name).Width(45).Title("Name");
columns.Bound(pl => pl.Own_Salutation).Width(45).Title("Salutation");
columns.Bound(pl => pl.Own_MailAddr).Width(45).Title("Mailing Addr");
columns.Bound(pl => pl.Own_City_St_Zip).Width(45).Title("City,State,Zip");
columns.Bound(pl => pl.Own_PropAddr).Width(45).Title("Property Address");
})
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => { read.Action("GetOwnerList", "Owners").Data("{ FileNum: " + @Model.FileNum + "}"); })
)
)
This will send a single parameter called 'FileNum' to GetOwnerList in the Owners controller. How would I set this up to send a second parameter along with FileNum?
Thank you.
答案1
得分: 1
以下是翻译好的部分:
在我的应用程序中,为了提高可读性,我使用了一个JavaScript函数名称来进行数据调用,如下所示:
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetOwnerList", "Owners").Data("ReadOwnerListData"))
)
然后,在您的JavaScript中:
function ReadOwnerListData() {
return {
FileNum: Json.Serialize(Model.FileNum),
SecondValue: [这里是第二个值]
};
}
英文:
What I have done in my applications for better readability is to use a JavaScript function name in the Data call like so:
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetOwnerList", "Owners").Data("ReadOwnerListData")})
)
then, in your JavaScript:
function ReadOwnerListData() {
return {
FileNum: Json.Serialize(Model.FileNum),
SecondValue: [second value here]
};
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论