我在創建的應用程序中調用編輯方法時遇到問題。在視圖中單擊一個ActionLink作爲參數應該將訂單號傳遞給Edit方法,並打開一個編輯頁面,其中包含填充在字段中的訂單的信息。然而,點擊鏈接後,我收到錯誤:空參數錯誤
The parameters dictionary contains a null entry for parameter 'orderNum' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ViewResult Edit(Int32)' in 'AddressUpdater.WebUI.Controllers.OrderController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
但是,該參數存在於URL中。以下是相關的方法:
public ViewResult Edit(int orderNum)
{
Order order = repository.Orders.First(o => o.OrderNumber == orderNum);
return View(order);
}
如果如果改變參數int? orderNum
頁面將呈現沒有錯誤,但沒有數據是存在的。
請發佈您的actionLink請 –
您如何調用url,更重要的是,您如何繪製路線? –
ActionLink發佈在下面。這裏是路由(這是默認值): 'routes.MapRoute( 「Default」,//路由名稱 「{controller}/{action}/{id}」,//帶參數的URL 新{controller =「Order」, action =「List」,id = UrlParameter.Optional} );' – ian