我创建了一个包含SearchModel和结果的视图表单。
以下是我的搜索模型。
public class UserViewModel
{
public string Status { get; set; }
public string Type { get; set; }
public string Search { get; set; }
public string SortBy { get; set; }
public string SortOrder { get; set; }
public IPagedList<Users> Users{ get; set; }
}
public ActionResult Index(UserViewModel filter, int? page)
{
filter.Users=GetUsersFromDatabase().ToList();
}
public ActionResult ToggleActive(bool IsActive, Guid Id)
{
// Set update operation to user
return RedirectToAction("Index", new { page = Request["page"] });
}
现在我想根据列表页面上的UserViewModel过滤器值在ToggleActive上重定向用户。我希望你明白我的观点。
如何传递仅搜索模型。请让我知道简单的方法。
在我看来,我创建了视图。
<a href="@Url.Action("ToggleActive", "User", new { IsActive = item.IsActive, Id = item.UserID, page = ViewData["CurrentPage"]})">
Active/Deactive
</a>
答案 0 :(得分:0)
确保您的视图已定义模型:
@model UserViewModel
将当前模型发送回控制器的ToggleActive动作:
public ActionResult ToggleActive(bool IsActive, Guid Id, int page, UserViewModel filter)
{
// Do stuff with the filter
// Set update operation to user
return RedirectToAction("Index", new { page = Request["page"] });
}
并更改您的操作网址以包含模型:
<a href="@Url.Action("ToggleActive", "User", new { IsActive = item.IsActive, Id = item.UserID, page = ViewData["CurrentPage"], filter = Model})">
Active/Deactive
</a>