开发者

The current request for action 'Index' on controller type 'DinnersController' is ambiguous between the following action methods [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center开发者_C百科. Closed 11 years ago.

I am getting this error after trying to implement paging support.

I am on this step of the html tutorial: http://nerddinnerbook.s3.amazonaws.com/Part8.htm


The error you are getting tells that ASP.NET MVC has found two actions with the same name and can't chose which to use.

If you have two Index-actions in your DinnersController.cs:

public ActionResult Index() {

and:

public ActionResult Index(int? page) {

Then you should remove the first Action. since the second is the 'updated' version of the first. The second Action accepts requests to:

/Dinners

/Dinners?page=2

/Dinners/Index

/Dinners/Index?page=2

And with the change in RegisterRoutes it also accepts requests to:

/Dinners/Page/2

You can have two Actions with the same name, providing one is for saving (postbacks), where you decorate the saving action with [AcceptVerbs(HttpVerbs.Post)] or just [HttpPost]


MVC does not support overloading of action methods in your controller. It is not possible to have two Index() actions with different method signatures on the same controller.

In order to make the example you are testing work, you must remove the Index() action which does not accept any parameters, and replace it with the action that takes a nullable int as a parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜