0
不知道爲什麼,一切看起來格式正常,但在嘗試訪問我的控制器中的函數時出現HTTP 404錯誤。這裏的ASPX:通過AJAX訪問URL時出現404錯誤
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;
}
}
我想我只是盯着這太長了。謝謝。
我猜想,您的網址是錯誤的。打開Firebug或Fiddler以查看您訪問的網址。我假設包裝是您當前的區域,並且PackageTracking是您的控制器,所以我不會驚訝地發現您請求http:// localhost:port/Packing/PackageTracking/Packing/PackageTracking/CheckIfPacked – hawkke
URL應該是好的: localhost:port/Packing/PackageTracking/CheckIfPacked –
該URL是正確的,代碼的位置不是。龐大的代碼庫。 –