I have created a View Form which include SearchModel and result as well.
Here below is my search model.
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"] });
}
Now I want to redirect user on ToggleActive based on UserViewModel filter values on listing page. I hope you get my point.
How to pass the search only model. Please let me know the easy way.
In my view I have created the view.
<a href="@Url.Action("ToggleActive", "User", new { IsActive = item.IsActive, Id = item.UserID, page = ViewData["CurrentPage"]})">
Active/Deactive
</a>
Make sure your view has defined the model:
@model UserViewModel
Send your current model back to the controller's ToggleActive action:
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"] });
}
And change your action url to include the model:
<a href="@Url.Action("ToggleActive", "User", new { IsActive = item.IsActive, Id = item.UserID, page = ViewData["CurrentPage"], filter = Model})">
Active/Deactive
</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.