这是我的 ActionResult
{
UsersModel um = new UsersModel();
um.Users = userRepository.GetAllUsers();
um.UserCustomers = userRepository.GetAllUserCustomerConnections();
um.UserTypes = enums.GetAllDescriptions(CodeType.UserType);
um.Customers = userRepository.GetAllCustomers();
um = SearchUsers(Request,um);
return View(um);
}
它使用函数 SearchUsers :
private UsersModel SearchUsers(HttpRequestBase request, UsersModel curModel)
{
try
{
// request parameters
string userName = request.Params["user-name"];
string firstName = request.Params["first-name"];
string lastName = request.Params["last-name"];
int status,type,businessId;
if (!string.IsNullOrWhiteSpace(userName))
curModel.Users = curModel.Users.Where(u => u.Username.Contains(userName));
if (!string.IsNullOrWhiteSpace(firstName))
curModel.Users = curModel.Users.Where(u => u.FirstName.Contains(firstName));
if (!string.IsNullOrWhiteSpace(lastName))
curModel.Users = curModel.Users.Where(u => u.LastName.Contains(lastName));
if (int.TryParse(request.Params["status-search"], out status))
curModel.Users = curModel.Users.Where(u => u.Status == status);
if (int.TryParse(request.Params["userTypes-search"], out type))
curModel.Users = curModel.Users.Where(u => u.UserType == type);
if (int.TryParse(request.Params["busi-name"], out businessId))
curModel.Users = curModel.Users.Where(u => u.LastCustomerId == businessId);
return curModel;
}
catch
{
return curModel;
}
}
现在我在我的视图中有一个 id 为“search-users”的按钮和我在 js 文件中的命令:
$('#search-users').click(function () {
});
如何将 HttpRequestBase 发布到控制器?