2016-05-11 2 views
1

SearchModelと結果を含むViewフォームを作成しました。MVC 4次のページの検索を続ける

以下は私の検索モデルです。

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

ビューがモデルを定義していることを確認してください:

@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"] }); 
} 

とモデルを含めるようにアクションのURLを変更します:

<a href="@Url.Action("ToggleActive", "User", new { IsActive = item.IsActive, Id = item.UserID, page = ViewData["CurrentPage"], filter = Model})"> 
              Active/Deactive 
             </a> 
+0

Can yoあなたのdownvoteを正当化してください? –

+0

Modelには既に公開IPagedListが含まれているため、モデルをアクションURLに直接渡すのは正しいですか? Users {get;セット; } – Anil

+0

私はdownvoteしませんでした。 – Anil

関連する問題