0
我是MVC的新手,目前我正在使用Postman来测试我的webapi方法函数。我意识到,如果我从路由中指定了不同的参数,我将在邮递员中获得一个MVC 4 +控制器中接受不同参数名称的方法
"message": "The requested resource does not support http method 'GET'." error
。我想知道是否可以在控制器中使用不同的参数名称?谢谢。
[ActionName("DefaultAction")]
// This method won't be callable because the argument name is different from the routing.
public virtual IEnumerable<CaseComment> Get(int CaseId)
{
// Implementation
}
[ActionName("DefaultAction")]
public virtual HttpResponseMessage Post(int CaseCommentId)
{
// Implementation
}
Routing:
config.Routes.MapHttpRoute(
name: "CaseComment",
routeTemplate: "api/v1/casecomment/{CaseCommentId}/{action}",
defaults: new { controller = "casecomment", CaseCommentId= RouteParameter.Optional, action = "DefaultAction" }
);