That empty string for productId
(in your default route) will get parsed to a null entry by the Framework, and since int
does not allow null
...you're getting the error.
Change:
public ViewResult Edit(int productId)
to
public ViewResult Edit(int? productId)
if you want to allow for the caller to not have to pass in a product id, which is what it looks like what you want to do based on the way your route is configured.
You could also re-configure your default route to pass in some known default for when no productId is supplied:
routes.MapRoute(
"Admin",
"Admin/{action}/{ productId}",
new { controller = "Admin", action = "Edit", productId= -1 }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…