我的每個控制器方法都需要重定向回到索引頁面,並將它們發回的模型對象發送回控制器。但是,在一個實例中,我需要與模型對象一起發送錯誤消息。下面是索引方法的簽名:無法在RedirectToAction上傳遞多個參數
public ViewResult Index(ZipCodeIndex search, string unspecifiedAction = "")
由於我只需要一個方法的錯誤消息,我使這個參數可選。這裏是我想從單獨行動重定向到索引:
//the parameter 'updateZip' is a model object of type ZipCodeIndex
return RedirectToAction("Index", new { search = updateZip, unspecifiedAction = "Error: Action could not be determined. IT has been notified and will respond shortly."});
這一切都捲起做的是將用戶發送回並顯示錯誤消息的原始頁面「對象引用未設置爲實例一個東西。」
EDIT
控制器後擊中RedirectToAction
它簡單地退出所述控制器,而不重定向到索引方法,和錯誤「不設置到對象的實例對象refrerence」出現在視圖。
沒有什麼是錯的代碼,您是否收到任何錯誤? – Satpal
什麼是'ZipCodeIndex'? – Satpal
我認爲問題是「search = updateZip」。請刪除此參數並重試。告訴我們結果。 –