【发布时间】:2016-04-02 16:48:12
【问题描述】:
我正在 Visual Studio 2012 上制作 MVC5 应用程序。
我编写了一个 AJAX 调用并让它正常工作,然后我将其 Web 服务器从之前设置的 IIS Express 切换到 IIS 7.5,现在我在运行 AJAX 调用时得到 404。
(如果我切换回 IIS Express,一切正常)
我有什么遗漏吗?
仅供参考,我先查看了此链接,但没有解决我的问题:asp.net mvc ajax post returns 404 not found
控制器代码:
[HttpPost]
public JsonResult GetExpenseData()
{
var expenses = new ExpenseGridModel();
expenses.Populate(); //todo: filter
return Json(expenses, JsonRequestBehavior.AllowGet);
}
AJAX 调用(在 feeGrid.cshtml 中):
<script type="text/javascript">
$().ready(function () {
var $editExpenseDiv = $('#editExpenseDiv');
$editExpenseDiv.hide();
$.ajax({
url: '/Main/GetExpenseData',
contentType: 'application/json; charset=utf-8',
type: 'POST'
})
.success(function (result) {
LoadGrid(result, $("#expenseTable"), $editExpenseDiv, "This is the EDIT EXPENSE Div.");
})
.error(function(xhr, status) {
alert(status);
});
});
</script>
索引.html:
--- BreadCrumb Bar ---
<br/><br/>
@{
Html.RenderPartial("_ExpenseGrid", Model.ExpenseGridModel);
}
<br/>
@{
Html.RenderPartial("_NotificationGrid", Model.NotificationGridModel);
}
路线配置:
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 = "Main", action = "Index", id = UrlParameter.Optional}
);
}
}
【问题讨论】:
-
检查网址“未找到”。您的站点在根目录中吗? localhost/main 还是 localhost/miSite/main?
-
虚拟目录指向 web 项目文件夹,加载页面正常,只是不是 AJAX 调用。错误指向:localhost/Main/GetExpenseData
标签: c# asp.net-mvc-5