Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

499
Visualizações
500 Internal: Multiple actions were found that match 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 AJAX call i get 2 errors as 500 (Internal Server Error)

  1. For TechViews
  2. For SView

and the response is "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 ,

  1. Removing HttpPost
  2. Re-Order HttpPost and Route
  3. Changing names for naming conntraints
  4. Removing FromBody in the param
  5. Changing the Method name and Parameter Type.

When i used only one post with no Route the same code works fine.

Where am i wrong?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Enable config.MapHttpAttributeRoutes() option in api routing configuration.

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);
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda