How to pass complex type data on Ajax binding
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?
If you use
e.data = modelData
it will bind correctly.
精彩评论