如何在 Ajax 绑定上传递复杂类型数据
Telerik ASP.NET MVC Q2 2011
我有一个 Ajax 绑定的网格:
@(Html.Telerik().Grid<IUser>()
.Name("UsersGrid")
.DataBinding(binding => binding.Ajax().Select("UsersGridSelect", "User", new { area = "Admin" }))
.ClientEvents(events => events.OnDataBinding("onGridRefresh"))
...
...
这是我的 onGridRefresh 处理程序:
function onGridRefresh(e)
{
var modelData =
{
Username: $('#SearchModel_Username').val(),
FirstName: $('#SearchModel_FirstName').val(),
LastName: $('#SearchModel_LastName').val(),
IsLocked: $('#SearchModel_IsLocked').is(':checked'),
ClientId: $('#SearchModel_ClientId').val(),
UserCode: $('#SearchModel_UserCode').val(),
ExpireDateFrom: $('#SearchModel_ExpireDateFrom').val(),
ExpireDateTo: $('#SearchModel_ExpireDateTo').val()
};
e.data = { searchModel: modelData };
}
这是我的控制器:
[GridAction]
public ActionResult UsersGridSelect(UserSearchModel searchModel)
{
IList<IUser> userList = searchModel == null ? new List<IUser>() : _repository.GetUsers(searchModel);
return View(new GridModel(userList));
}
我知道这个设置不起作用......但至少它演示了我所追求的。 当我将我的值作为单独的参数传递时,它可以工作:
public ActionResult UsersGridSelect(string Username, string Firstname, string LastName,....)
但我更愿意将它作为对象传递。有什么办法可以做到这一点吗?
Telerik ASP.NET MVC Q2 2011
I have a grid which is Ajax bound:
@(Html.Telerik().Grid<IUser>()
.Name("UsersGrid")
.DataBinding(binding => binding.Ajax().Select("UsersGridSelect", "User", new { area = "Admin" }))
.ClientEvents(events => events.OnDataBinding("onGridRefresh"))
...
...
This is my onGridRefresh handler:
function onGridRefresh(e)
{
var modelData =
{
Username: $('#SearchModel_Username').val(),
FirstName: $('#SearchModel_FirstName').val(),
LastName: $('#SearchModel_LastName').val(),
IsLocked: $('#SearchModel_IsLocked').is(':checked'),
ClientId: $('#SearchModel_ClientId').val(),
UserCode: $('#SearchModel_UserCode').val(),
ExpireDateFrom: $('#SearchModel_ExpireDateFrom').val(),
ExpireDateTo: $('#SearchModel_ExpireDateTo').val()
};
e.data = { searchModel: modelData };
}
And this is my controller:
[GridAction]
public ActionResult UsersGridSelect(UserSearchModel searchModel)
{
IList<IUser> userList = searchModel == null ? new List<IUser>() : _repository.GetUsers(searchModel);
return View(new GridModel(userList));
}
This setup does not work, I know... But at least it demonstrates what I am after.
When I pass in my values as seperate parameter it works:
public ActionResult UsersGridSelect(string Username, string Firstname, string LastName,....)
But I would prefere to pass it in as an object. Is there any way to accomplish that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你使用
e.data = modelData
它会正确绑定。
If you use
e.data = modelData
it will bind correctly.