通过AJAX访问URL时出现404错误

时间:2012-10-29 17:26:57

标签: c# jquery

不确定原因,一切看起来格式正常,但在尝试访问控制器中的某个功能时出现HTTP 404错误。这是aspx:

function CheckIfPacked() {
  if ($("#OrderNumber").val() != "") {
    var url = "/Packing/PackageTracking/CheckIfPacked";
    $.ajax({
      url: url,
      cache: false,
      data: "orderNumber=" + $("#OrderNumber").val() + "&actionyes=GetSalesOrder()",
      success: function (data) {
      var domElement = $(data);
      if (data != "") {
        $('#MessageDiv').append(domElement);
      }
    });
  }
}

这是控制器:

public Result CheckIfPacked(string orderNumber) {
   var mesEntity = new MESEntities();
   var packh = from packhead in mesEntity.Packing_Transaction_Headers
               where packhead.Order_No_ == orderNumber
               select packhead.Completed_by_Packer;
   if (packh.First() == 0)
   {
      return new Result { Success = true, Message = string.Format("You have not finished packing order {0}, are you sure you want to navigate away from this page?", orderNumber) };
   }
   else
   {
      return null;
   }
} 

我想我只是盯着这个太久了。感谢。

1 个答案:

答案 0 :(得分:0)

你的方法应该是静态的,你应该为你的函数使用webmethod属性:

[WebMethod]
public static Result CheckIfPacked(string orderNumber) {
   var mesEntity = new MESEntities();
   var packh = from packhead in mesEntity.Packing_Transaction_Headers
               where packhead.Order_No_ == orderNumber
               select packhead.Completed_by_Packer;
   if (packh.First() == 0)
   {
      return new Result { Success = true, Message = string.Format("You have not finished packing order {0}, are you sure you want to navigate away from this page?", orderNumber) };
   }
   else
   {
      return null;
   }
}