500 Internal: Multiple actions found matching the request
AJAX
$.ajax({
url: '../api/TechViews/SView',
type: 'POST',
dataType: 'json',
data: JSON.stringify({ Filter: JSON.stringify(eth.Data), Type: $('.productType.active').data('name'), Name: $('#txtView').val() }),
global: false,
contentType: "application/json; charset=utf-8",
success: function (data) {
alert('success');
},
error: function (xhrequest, ErrorText, thrownError) {
alert('Fail');
}
});
controller
[Route("SView")]
[HttpPost]
public string Post([FromBody]TechViewsModel value)
{
string result = string.Empty;
return result;
}
[Route("DView")]
[HttpPost]
public string Post([FromBody]TechViewsModel value)
{
string result = string.Empty;
return result;
}
The namespace used for Route
is AttributeRouting.Web.Mvc
. On the call AJAX
I get 2 errors like500 (Internal Server Error)
- For
TechViews
- For
SView
and the answer "Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nSystem.String Post
RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "LoginPage", id = UrlParameter.Optional }
);
}
I tried,
- Deleting
HttpPost
- Re-order
HttpPost
andRoute
- Changing names for naming
- Delete
FromBody
in parameter - Change method name and parameter type.
When I only used one post without Route
, the same code works fine.
Where am I going wrong?
source to share
Enable option config.MapHttpAttributeRoutes()
in routing api config.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
In global.asax.cs
GlobalConfiguration.Configure(WebApiConfig.Register);
source to share