行动控制器类型“DinnersController控制器'指数'当前请求是下面的操作方法之间的暧昧 [英] The current request for action 'Index' on controller type 'DinnersController' is ambiguous between the following action methods

查看:202
本文介绍了行动控制器类型“DinnersController控制器'指数'当前请求是下面的操作方法之间的暧昧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现分页支持后收到此错误。

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

我对HTML教程的这一步:<一href=\"http://nerddinnerbook.s3.amazonaws.com/Part8.htm\">http://nerddinnerbook.s3.amazonaws.com/Part8.htm

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

推荐答案

你所得到的错误告诉ASP.NET MVC已经找到同名的两个动作,不能选择使用哪个。

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.

如果你有两个索引操作你的 DinnersController.cs

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

public ActionResult Index() {

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:

/晚餐

/晚餐?页= 2

/晚餐/索引

/晚餐/指数?页= 2

和用的RegisterRoutes变化,也接受请求:

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

/晚餐/页/ 2

您可以有两个操作具有相同的名称,提供一个用于保存(回传),在那里你装饰与保存动作的[AcceptVerbs(HttpVerbs.Post)] 或只是 [HttpPost]

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]

这篇关于行动控制器类型“DinnersController控制器'指数'当前请求是下面的操作方法之间的暧昧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆