调用任何方法都会产生Get()的结果而不是它们的方法

时间:2017-01-28 23:10:20

标签: asp.net asp.net-web-api

这可能是一个措辞严厉的问题,这是我的第一个网络API,所以我可能会做一些完全错误的事情。我有我的Controller和我的模型,在我的Controller中我有3个方法,string [] Apples string []获取判断GetJudgmentByStateCaseId。我试图使用以下网址调用它们,但所有结果都来自Get()数据。

  • / API /判断
  • / API /苹果
  • / API / GetJudgmentByStateCaseId

`JudgmentController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebApplicationsWData.Models;

namespace WebApplicationsWData.Controllers
{
    public class JudgmentController : ApiController
    {
        public string[] Apples()
        {
            return new string[]
            {
                "as","B"
            };
        }

        public string[] Get()
        {
            return new string[]
            {
                "as","C"
            };
        }


        public Judgment GetJudgmentByStateCaseId(string State, string CaseId)
        {

            Judgment judgement = new Judgment
            {
                CaseId = "1",
                State = "MeVMe"


            };
            if (judgement == null)
                throw new HttpResponseException(HttpStatusCode.NotFound);
            return judgement;

        }




    }

`Judgment.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

    namespace WebApplicationsWData.Models
    {
        public class Judgment
        {
            [Required]
            public string State { get; set; }

            [Required]
            public string CaseId { get; set; }

        }
    }

这是我的RouteConfig

namespace WebApplicationsWData
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

1 个答案:

答案 0 :(得分:0)

好吧所以这个问题应该措辞如何支持asp api的多种方法。我想要多个get方法,所以这篇文章的重要内容就是答案`

https://www.codeproject.com/Tips/832045/Implementing-a-Basic-REST-Based-ASP-NET-Web-API-Se

是的,它现在有效:)