我有一個搜索視圖,它使用AJAX向服務器發送請求。根據存儲庫返回的響應對象,應該在搜索視圖(發送請求的視圖)上顯示對話框(使用Json對象填充數據),或者應該將用戶重定向到結果視圖(已填充來自響應的數據作爲視圖模型傳遞)。ASP.NET MVC3:如何使用AJAX創建文章時重定向到視圖?
現在我被告知(並且經驗豐富),當使用AJAX創建文章時,無法重定向。那麼是否有一些方法可以重定向到另一個視圖並傳遞視圖模型(如果該響應是從存儲庫獲取的),並且僅在顯示對話框結果時才發回Json對象。
即得到由搜索視圖貼到我的控制器動作看起來目前有些事情是這樣的:
[HttpPost]
public ActionResult SomeAction(SearchRequest reqData)
{
ResponseBase response = worker.PerformSearch(reqData);
if (response is ViewResponse)
{
//Redirect to "AnotherView" and pass response as the view model.
return View("AnotherView", response as ViewResponse);
}
else if (response is DialogResponse)
{
//Return the Json object.
return Json(new { type = "dialogresponse", data = response });
}
else
{
//To do: Put error handling code here.
throw new NotImplementedException();
}
}