2014-03-04 76 views
0

我有一個asp.net MVC 4應用有以下索引操作:如何重定向到mvc控制器上的另一個動作?

public ActionResult Index() 
{ 
    if (User.IsInRole("dealer")) 
    { 
     return View(db.Commissions.Where(c => c.Dealer.Name == User.Identity.Name)); 
    } 
    else 
    {//admin 
     return View(db.Commissions); 
    } 
} 

我想我的頁面重定向到另一個MVC行動稱爲過濾器,但不能把它與此代碼完成的:

$(function() { 
     jQuery.noConflict() 
     $("#datefrom").datepicker(); 
     $("#dateto").datepicker(); 

     $("#btnfilter").click(function() { 
      $.ajax({ 
       type: "get", 
       url: "/commissions/filter/", 
       data:{'from':$("#datefrom").val(),to:$("#dateto").val()} 
       ,success: function(result){ 
        if(result.Success){ 
         window.location = "/Filter/Commissions" + $("#datefrom").val() + $("#dateto").val(); 
        } 
       } 
      }); 
     }); 

    }); 

這是篩選器操作:

public ActionResult Filter(DateTime from, DateTime to) 
     { 
      if (User.IsInRole("dealer")) 
      { 
       return View(db.Commissions.Where(c => c.Dealer.Name == User.Identity.Name && c.CreatedDate>=from && c.CreatedDate <=to)); 
      } 
      else 

      {//admin 
       var test = db.Commissions.Where(c => c.CreatedDate >= from && c.CreatedDate <= to); 
       return View(db.Commissions.Where(c=>c.CreatedDate >= from && c.CreatedDate <= to)); 
      } 
     } 

的篩選器操作被擊中的服務器上,但我得到以下錯誤,當我在看小提琴手:

[InvalidOperationException: The view 'filter' or its master was not found or no view engine supports the searched locations. The following locations were 

我該如何解決這個問題?

+2

查看文件Filter.cshtml是否存在? – 2014-03-04 05:29:57

+1

我認爲,在ajax調用成功之後,您傳遞的是錯誤的url。而不是「/過濾器/佣金」,必須使用「/佣金/過濾器」 – 111

回答

0

試試這個,但我有一個懷疑在你的代碼中,你在返回true/false在過濾器操作。

$(function() { 
    jQuery.noConflict() 
    $("#datefrom").datepicker(); 
    $("#dateto").datepicker(); 

    $("#btnfilter").click(function() { 
     $.ajax({ 
      type: "get", 
      url: '@Url.Action("filter","commissions")', 
      data:{'from':$("#datefrom").val(),to:$("#dateto").val()}, 
      success: function(result){ 
       if(result.Success){ 
        window.location.href = '@Url.Action("filter","commissions",new{from=$("#datefrom").val(),to=$("#dateto").val()})'; 
       } 
      } 
     }); 
    }); 

}); 
+0

過濾器操作被擊中,這不是問題 – user603007

+0

那麼什麼是年的問題? – Amit

+0

結果不會更新,即結果不會被過濾 – user603007

相關問題