- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 Action ,每当我显式调用第二个 Action 时,第一个 Action 仍会被调用。我需要能够在 mysite.com/api/Awesome/GetSomeExamples 中编写,而不总是触发 GetAllClasses
public class AwesomeController : Controller
{
public IEnumerable<myClass> GetAllClasses()
{
//...some stuff
}
public IEnumerable<string> GetSomeExamples()
{
//...some stuff
}
//... also have some more actions which take in one parameter
}
我的路由是这样的,但不工作
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ActionApi",
url: "api/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
我得到的错误:发现多个与请求匹配的操作
最佳答案
您正在使用 Web API。
与普通 MVC 操作的不同之处在于 Web API 查看 HTTP 动词来确定要调用的操作。在这种情况下,您有两个以 Get
但是,这会触发一个错误:Multiple actions were found that match the request...
它不应该同时调用这两个 Action 。
您需要的网址是:
mysite.com/api/Awesome/
从那里,Web API 将调用一个以 Get
开头的方法。您需要删除其他 get 方法并将其放在不同的 Controller 中。 Web API 假设每个 http 动词有一个 Action
关于asp.net-mvc - 路由、打错 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16441976/
假设您有一个系统,其中相当长的键值可以在屏幕上、通过电子邮件或纸张准确地传达给用户;但是用户需要能够通过电话读取 key 或通过读取 key 并将其输入回其他界面来准确地将 key 传达给您。 对 k
在 route.php 中,我定义了一个到 Controller 的路由,上面有 2 个标记。 Route::get('/{category}/{slug}', 'projectController@
我有两个 Action ,每当我显式调用第二个 Action 时,第一个 Action 仍会被调用。我需要能够在 mysite.com/api/Awesome/GetSomeExamples 中编写,
我有两个 Action ,每当我显式调用第二个 Action 时,第一个 Action 仍会被调用。我需要能够在 mysite.com/api/Awesome/GetSomeExamples 中编写,
我是一名优秀的程序员,十分优秀!