【问题标题】:Order Status post method not getting called web api 2订单状态发布方法没有被调用 web api 2
【发布时间】:2019-04-27 13:02:28
【问题描述】:

使用邮递员时,我的 Post 命令未命中。 post命令用于更改交货的订单状态

namespace DeliveryGo.Controllers
{
    public class DeliveryController : ApiController
    {


        public IHttpActionResult Get()
        {
            string retJson;
            string constring = ConfigurationManager.AppSettings["DeliveryGocs"].ToString();   


            string sql = "SELECT * FROM Deliverys AS A LEFT OUTER JOIN  DeliveryLines AS B ON A.id = B.DeliveryId;";

            using (var connection = new SqlConnection(constring))
            {
                var orderDictionary = new Dictionary<int, DeliverysItems>();


                var list = connection.Query<DeliverysItems, DeliverItemLines, DeliverysItems>(
                    sql,
                    (order, orderDetail) =>
                    {
                        DeliverysItems orderEntry;

                        if (!orderDictionary.TryGetValue(order.id, out orderEntry))
                        {
                            orderEntry = order;
                            orderEntry.DeliveryLines = new List<DeliverItemLines>();
                            orderDictionary.Add(orderEntry.id, orderEntry);
                        }

                        orderEntry.DeliveryLines.Add(orderDetail);
                        return orderEntry;
                    })
                .Distinct()
                .ToList();


                retJson = JsonConvert.SerializeObject(list);

                if (list.Count > 0)
                {
                    var response = this.Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent(retJson, Encoding.UTF8, "application/json");

                    return ResponseMessage(response);
                }else
                {
                    var response = this.Request.CreateResponse(HttpStatusCode.NoContent);
                    response.Content = new StringContent(retJson, Encoding.UTF8, "application/json");

                    return ResponseMessage(response);

                }



            }
        }
        // POST api/values
        public void Post([FromBody]string value)
        {
        }
        [HttpPost]
        public void ChangeOrderStatus(int  enumValue, string SopOrderNumber)
        {


            //lets get the order status here
            int orderStatus = (int)enumValue;

            string connectionString = Constants.DeliveryGocs;
            using (IDbConnection db = new SqlConnection(connectionString))
            {

                string sql = "UPDATE Deliverys SET OrderStatus = +"+enumValue+ " WHERE SopOrderNumber ='" +SopOrderNumber +"'";
                db.Execute(sql);



            }
        }

    }
}

如您所见,我在 postman 中使用表单参数中的值调用该方法,但是当我在该方法中调试断点时没有被命中,是不是我做错了什么。

我在这里发布我的网络路线,看看最有什么要求。

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 }
        );
    }
}

【问题讨论】:

  • 希望有人停止对我投反对票,我提供了大量代码和证据!

标签: c# asp.net-web-api2


【解决方案1】:

您收到 204 并且当您没有从您的 POST 方法返回任何响应时,这是成功的。这对我来说是一个打击。但是你说它没有命中方法,如果你的意思是断点命中,那可能是因为运行时和现有二进制文件之间的汇编问题。但总的来说,这对我来说似乎很受欢迎:)

【讨论】:

  • @prd 你不需要为什么它没有被击中吗?。
猜你喜欢
  • 2017-12-19
  • 2017-08-24
  • 1970-01-01
  • 2016-06-12
  • 1970-01-01
  • 2015-02-17
  • 1970-01-01
  • 2014-08-22
  • 1970-01-01
相关资源
最近更新 更多