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

倾然丶 夕夏残阳落幕 提交于 2019-12-23 07:58:23

问题


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


回答1:


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]




回答2:


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.



来源:https://stackoverflow.com/questions/7574902/the-current-request-for-action-index-on-controller-type-dinnerscontroller-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!