简体   繁体   English

单个controller ASP.NET Web API中有多个GET方法

[英]Single controller with multiple GET methods in ASP.NET Web API

In Web API I had a class of similar structure:在 Web API 中,我有一个类似结构的 class:

public class SomeController : ApiController
{
    [WebGet(UriTemplate = "{itemSource}/Items")]
    public SomeValue GetItems(CustomParam parameter) { ... }

    [WebGet(UriTemplate = "{itemSource}/Items/{parent}")]
    public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }
}

Since we could map individual methods, it was very simple to get the right request at the right place.由于我们可以使用 map 个单独的方法,因此在正确的位置获得正确的请求非常简单。 For similar class which had only a single GET method but also had an Object parameter, I successfully used IActionValueBinder .对于类似的 class 它只有一个GET方法但也有一个Object参数,我成功地使用IActionValueBinder However, in the case described above I get the following error:但是,在上述情况下,我收到以下错误:

Multiple actions were found that match the request: 

SomeValue GetItems(CustomParam parameter) on type SomeType

SomeValue GetChildItems(CustomParam parameter, SomeObject parent) on type SomeType

I am trying to approach this problem by overriding the ExecuteAsync method of ApiController but with no luck so far.我试图通过覆盖ApiControllerExecuteAsync方法来解决这个问题,但到目前为止没有运气。 Any advice on this issue?关于这个问题有什么建议吗?

Edit: I forgot to mention that now I am trying to move this code on ASP.NET Web API which has a different approach to routing.编辑:我忘了提及,现在我正在尝试将此代码移动到 ASP.NET Web API 上,它具有不同的路由方法。 The question is, how do I make the code work on ASP.NET Web API?问题是,如何让代码在 ASP.NET Web API 上运行?

This is the best way I have found to support extra GET methods and support the normal REST methods as well.这是我发现支持额外 GET 方法和支持普通 REST 方法的最佳方式。 Add the following routes to your WebApiConfig:将以下路由添加到您的 WebApiConfig:

routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" });
routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}");
routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) });
routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new {action = "Post"}, new {httpMethod = new HttpMethodConstraint(HttpMethod.Post)});

I verified this solution with the test class below.我用下面的测试类验证了这个解决方案。 I was able to successfully hit each method in my controller below:我能够成功地在我的控制器中点击下面的每个方法:

public class TestController : ApiController
{
    public string Get()
    {
        return string.Empty;
    }

    public string Get(int id)
    {
        return string.Empty;
    }

    public string GetAll()
    {
        return string.Empty;
    }

    public void Post([FromBody]string value)
    {
    }

    public void Put(int id, [FromBody]string value)
    {
    }

    public void Delete(int id)
    {
    }
}

I verified that it supports the following requests:我确认它支持以下请求:

GET /Test
GET /Test/1
GET /Test/GetAll
POST /Test
PUT /Test/1
DELETE /Test/1

Note That if your extra GET actions do not begin with 'Get' you may want to add an HttpGet attribute to the method.请注意,如果您的额外 GET 操作不以“Get”开头,您可能需要向该方法添加 HttpGet 属性。

Go from this:从这里开始:

config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
            new { id = RouteParameter.Optional });

To this:对此:

config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}/{id}",
            new { id = RouteParameter.Optional });

Hence, you can now specify which action (method) you want to send your HTTP request to.因此,您现在可以指定要将 HTTP 请求发送到的操作(方法)。

posting to "http://localhost:8383/api/Command/PostCreateUser" invokes:发布到“http://localhost:8383/api/Command/PostCreateUser”调用:

public bool PostCreateUser(CreateUserCommand command)
{
    //* ... *//
    return true;
}

and posting to "http://localhost:8383/api/Command/PostMakeBooking" invokes:并发布到“http://localhost:8383/api/Command/PostMakeBooking”调用:

public bool PostMakeBooking(MakeBookingCommand command)
{
    //* ... *//
    return true;
}

I tried this in a self hosted WEB API service application and it works like a charm :)我在一个自托管的 WEB API 服务应用程序中尝试了这个,它的工作原理非常棒:)

I find attributes to be cleaner to use than manually adding them via code.我发现属性比通过代码手动添加它们更易于使用。 Here is a simple example.这是一个简单的例子。

[RoutePrefix("api/example")]
public class ExampleController : ApiController
{
    [HttpGet]
    [Route("get1/{param1}")] //   /api/example/get1/1?param2=4
    public IHttpActionResult Get(int param1, int param2)
    {
        Object example = null;
        return Ok(example);
    }

}

You also need this in your webapiconfig你的 webapiconfig 中也需要这个

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

config.Routes.MapHttpRoute(
    name: "ActionApi",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

Some Good Links http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api This one explains routing better.一些不错的链接http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api这个更好地解释了路由。 http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

You need to define further routes in global.asax.cs like this:您需要在 global.asax.cs 中定义更多路由,如下所示:

routes.MapHttpRoute(
    name: "Api with action",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

With the newer Web Api 2 it has become easier to have multiple get methods.使用较新的 Web Api 2,拥有多个 get 方法变得更加容易。

If the parameter passed to the GET methods are different enough for the attribute routing system to distinguish their types as is the case with int s and Guid s you can specify the expected type in the [Route...] attribute如果传递给GET方法的参数差异足以让属性路由系统区分它们的类型,就像int s 和Guid s 的情况一样,您可以在[Route...]属性中指定预期类型

For example -例如 -

[RoutePrefix("api/values")]
public class ValuesController : ApiController
{

    // GET api/values/7
    [Route("{id:int}")]
    public string Get(int id)
    {
       return $"You entered an int - {id}";
    }

    // GET api/values/AAC1FB7B-978B-4C39-A90D-271A031BFE5D
    [Route("{id:Guid}")]
    public string Get(Guid id)
    {
       return $"You entered a GUID - {id}";
    }
} 

For more details about this approach, see here http://nodogmablog.bryanhogan.net/2017/02/web-api-2-controller-with-multiple-get-methods-part-2/有关此方法的更多详细信息,请参见此处http://nodogmablog.bryanhogan.net/2017/02/web-api-2-controller-with-multiple-get-methods-part-2/

Another options is to give the GET methods different routes.另一种选择是为GET方法提供不同的路由。

    [RoutePrefix("api/values")]
    public class ValuesController : ApiController
    {
        public string Get()
        {
            return "simple get";
        }

        [Route("geta")]
        public string GetA()
        {
            return "A";
        }

        [Route("getb")]
        public string GetB()
        {
            return "B";
        }
   }

See here for more details - http://nodogmablog.bryanhogan.net/2016/10/web-api-2-controller-with-multiple-get-methods/有关更多详细信息,请参见此处 - http://nodogmablog.bryanhogan.net/2016/10/web-api-2-controller-with-multiple-get-methods/

In ASP.NET Core 2.0 you can add Route attribute to the controller:在 ASP.NET Core 2.0 中,您可以将Route属性添加到控制器:

[Route("api/[controller]/[action]")]
public class SomeController : Controller
{
    public SomeValue GetItems(CustomParam parameter) { ... }

    public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }
}

In VS 2019, this works with ease:在 VS 2019 中,这很容易实现:

[Route("api/[controller]/[action]")] //above the controller class

And in the code:在代码中:

[HttpGet]
[ActionName("GetSample1")]
public Ilist<Sample1> GetSample1()
{
    return getSample1();
}
[HttpGet]
[ActionName("GetSample2")]
public Ilist<Sample2> GetSample2()
{
    return getSample2();
}
[HttpGet]
[ActionName("GetSample3")]
public Ilist<Sample3> GetSample3()
{
    return getSample3();
}
[HttpGet]
[ActionName("GetSample4")]
public Ilist<Sample4> GetSample4()
{
    return getSample4();
}

You can have multiple gets like above mentioned.您可以像上面提到的那样有多个获取。

I was trying to use Web Api 2 attribute routing to allow for multiple Get methods, and I had incorporated the helpful suggestions from previous answers, but in the Controller I had only decorated the "special" method (example):我试图使用 Web Api 2 属性路由来允许多个 Get 方法,并且我已经合并了以前答案中的有用建议,但是在控制器中我只装饰了“特殊”方法(示例):

[Route( "special/{id}" )]
public IHttpActionResult GetSomethingSpecial( string id ) {

...without also also placing a [RoutePrefix] at the top of the Controller: ...也没有在控制器顶部放置 [RoutePrefix]:

[RoutePrefix("api/values")]
public class ValuesController : ApiController

I was getting errors stating that no Route was found matching the submitted URI.我收到错误,指出找不到与提交的 URI 匹配的路由。 Once I had both the [Route] decorating the method as well as [RoutePrefix] decorating the Controller as a whole, it worked.一旦我让 [Route] 装饰方法以及 [RoutePrefix] 将控制器作为一个整体装饰,它就起作用了。

**Add Route function to direct the routine what you want**
    public class SomeController : ApiController
    {
        [HttpGet()]
        [Route("GetItems")]
        public SomeValue GetItems(CustomParam parameter) { ... }

        [HttpGet()]
        [Route("GetChildItems")]
        public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }
    }

The lazy/hurry alternative (Dotnet Core 2.2):懒惰/匆忙的选择(Dotnet Core 2.2):

[HttpGet("method1-{item}")]
public string Method1(var item) { 
return "hello" + item;}

[HttpGet("method2-{item}")]
public string Method2(var item) { 
return "world" + item;}

Calling them :打电话给他们:

localhost:5000/api/controllername/method1-42本地主机:5000/api/控制器名称/方法1-42

"hello42" “你好42”

localhost:5000/api/controllername/method2-99本地主机:5000/api/控制器名/method2-99

"world99" “world99”

By default [Route("api/[controller]") will generated by .Net Core/Asp.Net Web API.You need to modify little bit,just add [Action] like [Route("api/[controller]/[action]")].默认情况下 [Route("api/[controller]") 将由 .Net Core/Asp.Net Web API 生成。您需要稍微修改一下,只需添加 [Action] 像 [Route("api/[controller]/[行动]”)]。 I have mentioned a dummy solution:我提到了一个虚拟解决方案:

// Default generated controller
//
[Route("api/[controller]")
public class myApiController : Controller
{
    [HttpGet]
    public string GetInfo()
    {
        return "Information";
    }
}

//
//A little change would do the magic
//

[Route("api/[controller]/[action]")]
public class ServicesController : Controller
{
    [HttpGet]
    [ActionName("Get01")]
    public string Get01()
    {
        return "GET 1";
    }

    [HttpGet]
    [ActionName("Get02")]
    public string Get02()
    {
        return "Get 2";
    }
    
    [HttpPost]
    [ActionName("Post01")]
    public HttpResponseMessage Post01(MyCustomModel01 model)
    {
        if (!ModelState.IsValid)
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
        
        //.. DO Something ..
        return Request.CreateResonse(HttpStatusCode.OK, "Optional Message");
    }
    
    [HttpPost]
    [ActionName("Post02")]
    public HttpResponseMessage Post02(MyCustomModel02 model)
    {
        if (!ModelState.IsValid)
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
        
        //.. DO Something ..
        return Request.CreateResonse(HttpStatusCode.OK, "Optional Message");
    }


}

Have you tried switching over to WebInvokeAttribute and setting the Method to "GET"?您是否尝试过切换到 WebInvokeAttribute 并将方法设置为“GET”?

I believe I had a similar problem and switched to explicitly telling which Method (GET/PUT/POST/DELETE) is expected on most, if not all, my methods.我相信我有一个类似的问题,并切换到明确告诉我的大多数方法(如果不是全部)预期使用哪种方法(GET/PUT/POST/DELETE)。

public class SomeController : ApiController
{
    [WebInvoke(UriTemplate = "{itemSource}/Items"), Method="GET"]
    public SomeValue GetItems(CustomParam parameter) { ... }

    [WebInvoke(UriTemplate = "{itemSource}/Items/{parent}", Method = "GET")]
    public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }
}

The WebGet should handle it but I've seen it have some issues with multiple Get much less multiple Get of the same return type. WebGet应该处理它,但我已经看到它有一些问题,多个 Get 少了多个相同返回类型的多个 Get。

[Edit: none of this is valid with the sunset of WCF WebAPI and the migration to ASP.Net WebAPI on the MVC stack] [编辑:随着 WCF WebAPI 的日落和在 MVC 堆栈上迁移到 ASP.Net WebAPI,这些都无效]

I am not sure if u have found the answer, but I did this and it works我不确定你是否找到了答案,但我做到了,并且有效

public IEnumerable<string> Get()
{
    return new string[] { "value1", "value2" };
}

// GET /api/values/5
public string Get(int id)
{
    return "value";
}

// GET /api/values/5
[HttpGet]
public string GetByFamily()
{
    return "Family value";
}

Now in global.asx现在在 global.asx

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapHttpRoute(
    name: "DefaultApi2",
    routeTemplate: "api/{controller}/{action}",
    defaults: new { id = RouteParameter.Optional }
);

routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

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

None of the above examples worked for my personal needs.以上示例均不适合我的个人需求。 The below is what I ended up doing.下面是我最终做的。

 public class ContainsConstraint : IHttpRouteConstraint
{       
    public string[] array { get; set; }
    public bool match { get; set; }

    /// <summary>
    /// Check if param contains any of values listed in array.
    /// </summary>
    /// <param name="param">The param to test.</param>
    /// <param name="array">The items to compare against.</param>
    /// <param name="match">Whether we are matching or NOT matching.</param>
    public ContainsConstraint(string[] array, bool match)
    {

        this.array = array;
        this.match = match;
    }

    public bool Match(System.Net.Http.HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
    {
        if (values == null) // shouldn't ever hit this.                   
            return true;

        if (!values.ContainsKey(parameterName)) // make sure the parameter is there.
            return true;

        if (string.IsNullOrEmpty(values[parameterName].ToString())) // if the param key is empty in this case "action" add the method so it doesn't hit other methods like "GetStatus"
            values[parameterName] = request.Method.ToString();

        bool contains = array.Contains(values[parameterName]); // this is an extension but all we are doing here is check if string array contains value you can create exten like this or use LINQ or whatever u like.

        if (contains == match) // checking if we want it to match or we don't want it to match
            return true;
        return false;             

    }

To use the above in your route use:要在您的路线中使用上述内容,请使用:

config.Routes.MapHttpRoute("Default", "{controller}/{action}/{id}", new { action = RouteParameter.Optional, id = RouteParameter.Optional}, new { action = new ContainsConstraint( new string[] { "GET", "PUT", "DELETE", "POST" }, true) });

What happens is the constraint kind of fakes in the method so that this route will only match the default GET, POST, PUT and DELETE methods.发生的是方法中的约束类型的伪造,因此该路由将仅匹配默认的 GET、POST、PUT 和 DELETE 方法。 The "true" there says we want to check for a match of the items in array.那里的“true”表示我们要检查数组中的项目是否匹配。 If it were false you'd be saying exclude those in the strYou can then use routes above this default method like:如果它是假的,您会说排除 strYou 中的那些然后可以使用此默认方法之上的路由,例如:

config.Routes.MapHttpRoute("GetStatus", "{controller}/status/{status}", new { action = "GetStatus" });

In the above it is essentially looking for the following URL => http://www.domain.com/Account/Status/Active or something like that.在上面它本质上是在寻找以下 URL => http://www.domain.com/Account/Status/Active或类似的东西。

Beyond the above I'm not sure I'd get too crazy.除了上述之外,我不确定我是否会变得太疯狂。 At the end of the day it should be per resource.归根结底,它应该是每个资源。 But I do see a need to map friendly urls for various reasons.但我确实认为出于各种原因需要映射友好的 url。 I'm feeling pretty certain as Web Api evolves there will be some sort of provision.我很确定随着 Web Api 的发展,将会有某种规定。 If time I'll build a more permanent solution and post.如果有时间我会建立一个更永久的解决方案并发布。

Couldn't make any of the above routing solutions work -- some of the syntax seems to have changed and I'm still new to MVC -- in a pinch though I put together this really awful (and simple) hack which will get me by for now -- note, this replaces the "public MyObject GetMyObjects(long id)" method -- we change "id"'s type to a string, and change the return type to object.无法使上述任何路由解决方案起作用——有些语法似乎已经改变,我还是 MVC 的新手——虽然我把这个非常糟糕(而且简单)的 hack 放在了一起,但它会让我受益匪浅现在——注意,这取代了“public MyObject GetMyObjects(long id)”方法——我们将“id”的类型更改为字符串,并将返回类型更改为对象。

// GET api/MyObjects/5
// GET api/MyObjects/function
public object GetMyObjects(string id)
{
    id = (id ?? "").Trim();

    // Check to see if "id" is equal to a "command" we support
    // and return alternate data.

    if (string.Equals(id, "count", StringComparison.OrdinalIgnoreCase))
    {
        return db.MyObjects.LongCount();
    }

    // We now return you back to your regularly scheduled
    // web service handler (more or less)

    var myObject = db.MyObjects.Find(long.Parse(id));
    if (myObject == null)
    {
        throw new HttpResponseException
        (
            Request.CreateResponse(HttpStatusCode.NotFound)
        );
    }

    return myObject;
}

If you have multiple Action within same file then pass the same argument eg Id to all Action.如果您在同一个文件中有多个操作,则将相同的参数(例如 Id)传递给所有操作。 This is because action only can identify Id, So instead of giving any name to argument only declare Id like this.这是因为动作只能识别Id,所以不要给参数任何名称,只像这样声明Id。


[httpget]
[ActionName("firstAction")] firstAction(string Id)
{.....
.....
}
[httpget]
[ActionName("secondAction")] secondAction(Int Id)
{.....
.....
}
//Now go to webroute.config file under App-start folder and add following
routes.MapHttpRoute(
name: "firstAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);

routes.MapHttpRoute(
name: "secondAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);

Simple Alternative简单替代

Just use a query string.只需使用查询字符串。

Routing路由

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

Controller控制器

public class TestController : ApiController
{
    public IEnumerable<SomeViewModel> Get()
    {
    }

    public SomeViewModel GetById(int objectId)
    {
    }
}

Requests要求

GET /Test
GET /Test?objectId=1

Note笔记

Keep in mind that the query string param should not be "id" or whatever the parameter is in the configured route.请记住,查询字符串参数不应是“id”或配置路由中的任何参数。

Specifying the base path in the [Route] attribute and then adding to the base path in the [HttpGet] worked for me.[Route]属性中指定基本路径,然后添加到[HttpGet]的基本路径对我[HttpGet] You can try:你可以试试:

    [Route("api/TestApi")]      //this will be the base path
    public class TestController : ApiController
    {
        [HttpGet]  //example call: 'api/TestApi'
        public string Get()
        {
            return string.Empty;
        }
    
        [HttpGet("{id}")]  //example call: 'api/TestApi/4'
        public string GetById(int id) //method name won't matter
        {
            return string.Empty;
        }
    
        //....

Took me a while to figure since I didn't want to use [Route] multiple times.我花了一段时间才弄清楚,因为我不想多次使用[Route]

The concept of multiple methods in a single asp.net web api controller makes it easier to have more than 1 method in code.单个 asp.net web api controller 中的多个方法的概念使得在代码中拥有多个方法变得更容易。

I was able to implement following the steps in the above solutions and came up with this final code我能够按照上述解决方案中的步骤实施并得出最终代码

In the WebApiConfig.cs,set up the following Route config, in this order在 WebApiConfig.cs 中,按此顺序设置以下 Route 配置

 public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.Routes.MapHttpRoute(
                name: "DefaultApiAction",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.MapHttpAttributeRoutes();


        }
    }

Then in your controller reference the [HttpGet] for GET or [HttpPost] for POST with [ActionName] see sample code below然后在您的 controller 中,使用 [ActionName] 引用 GET 的 [HttpGet] 或 POST 的 [HttpPost] 参见下面的示例代码

namespace WebRESTApi.Controllers
{
    //[RoutePrefix("api/Test")]
    public class TestController : ApiController
    {

 

        [HttpGet]
        [ActionName("AllEmailWithDisplayname")]
        public string AllEmailWithDisplayname()
        {
          
            return "values";
        }


 

        [HttpPost]
        [ActionName("Authenticate")]
        // POST: api/Authenticate
        public object Authenticate([FromBody()] object Loginvalues)
        {
 
                return true;
        
        }


        [HttpPost]
        [ActionName("ShowCredential")]
        // POST:  api/Showcredential
        public object Showcredential([FromBody()] object Loginvalues)
        {

            
            return "Username: " 


        }



    }
}

you can then consume the different methods via client or postman using the format然后您可以使用格式通过客户端或 postman 使用不同的方法

http://url/api/controller/actionname http://url/api/controller/actionname

Modify the WebApiConfig and add at the end another Routes.MapHttpRoute like this:修改WebApiConfig并在最后添加另一个 Routes.MapHttpRoute,如下所示:

config.Routes.MapHttpRoute(
                name: "ServiceApi",
                routeTemplate: "api/Service/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Then create a controller like this:然后创建一个这样的控制器:

public class ServiceController : ApiController
{
        [HttpGet]
        public string Get(int id)
        {
            return "object of id id";
        }
        [HttpGet]
        public IQueryable<DropDownModel> DropDowEmpresa()
        {
            return db.Empresa.Where(x => x.Activo == true).Select(y =>
                  new DropDownModel
                  {
                      Id = y.Id,
                      Value = y.Nombre,
                  });
        }

        [HttpGet]
        public IQueryable<DropDownModel> DropDowTipoContacto()
        {
            return db.TipoContacto.Select(y =>
                  new DropDownModel
                  {
                      Id = y.Id,
                      Value = y.Nombre,
                  });
        }

        [HttpGet]
        public string FindProductsByName()
        {
            return "FindProductsByName";
        }
}

This is how I solved it.我就是这样解决的。 I hope it will help someone.我希望它会帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM