【问题标题】:How can I send a date using a AXIOS Get?如何使用 AXIOS Get 发送日期?
【发布时间】:2019-10-01 13:06:00
【问题描述】:

我需要发送类似的日期

        2007/08/01 00:00

作为我的 AXIOS GET 中的值之一

      https://restapi.azurewebsites.net/api/PublicationReport/" +
      dbid +
      "/" +
      sortDate

如您所知,它对 Web API 控制器造成严重破坏

        <Route("api/PublicationReport/{dbid}/{sortDate}")>

控制器认为每个“/”都是一个新参数。

是否有必须使用的特殊格式或者我需要将其作为 json 对象发送?

我去了

      params: {
      dbid: dbid,
      sortDate: sortDate
    },

在客户端和服务器端以下

Public Function GetValues(dbid As Integer, sortDate As String) As String

【问题讨论】:

    标签: javascript c# asp.net-core .net-core asp.net-core-mvc


    【解决方案1】:

    你可以像这样创建一个对象:

    public class SomeQuery
    {
        public string SomeParameter { get; set; }
        public int? SomeParameter2 { get; set; }
    }
    

    然后在控制器中做这样的事情:

    [HttpGet]
    public IActionResult FindSomething([FromQuery] SomeQuery query)
    {
        // Your implementation goes here..
        //then you can access query value using HttpContext.Request.Query
    }
    

    或使用方法参数

    [HttpGet]
    public IActionResult FindSomething(string value1, string value2)
    

    【讨论】:

    • 我使用了 params 方法并更新了我的问题 - 谢谢
    猜你喜欢
    • 2020-03-28
    • 2018-04-24
    • 2019-05-29
    • 1970-01-01
    • 2019-10-21
    • 2021-11-29
    • 1970-01-01
    • 2020-08-16
    • 2020-10-24
    相关资源
    最近更新 更多