0
我想使用劫持做一個使用mvc的單頁web應用程序。我發現的問題是如何切換控制器以有效方式返回的佈局。Asp.net MVC hijaxing返回視圖修復
最明顯的非有效的解決方案是使用每個控制器上運行此代碼:
if (Request.IsAjaxRequest())
{
return PartialView();
}
else
{
viewdata["controller"]= "x"; viewdata["action"]= "y";
return View("defaultview"); //I need view data because only one template main
//view is returned and based on the viewdata the main
//view loads the right partial view inside it
}
有沒有辦法做到上面的代碼更簡單的方法?也許使用自定義的viewresult,它會檢查,如果請求是AJAX,並返回正確的視圖。或者也許是某種基本控制器?我不知道如何實施這兩個想法,所以任何指導都會很棒。