我有一个带有提交按钮的 ajax 表单,但是当我单击提交按钮时,我得到一个 404 page not found 错误。
我的部分观点:
@using (Ajax.BeginForm("Index", "Maps", null, ajaxOptions, new { @class = "form-search" }))
{
...
...
<button type="submit" class="btn">Search</button>
}
ajaxOptions 变量定义如下:
var ajaxOptions = new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "filter-results",
LoadingElementId = "filter-loading",
LoadingElementDuration = 2000,
OnFailure = "showAjaxError",
Url = Url.Action("Index")
};
这在我的浏览器(Chrome)中呈现如下:
<form action="/Maps" class="form-search" data-ajax="true" data-ajax-failure="showAjaxError" data-ajax-loading="#filter-loading" data-ajax-loading-duration="2000" data-ajax-mode="replace" data-ajax-update="#filter-results" data-ajax-url="/Maps" id="form0" method="post"> <div class="well well-small">
<div class="input-append">
<input type="text" class="span3">
<button type="submit" class="btn">Search</button>
</div>
<div class="input-prepend pull-right">
<button type="submit" class="btn">Items Per Page</button>
<input type="number" name="ItemsPerPage" class="span1" value="10">
</div>
</div>
</form>
404 错误说:
Requested URL: /Maps
我可以将它粘贴到我的浏览器中,它可以工作:
http://localhost:7374/Maps
我想我引用了正确的 javascript 文件 - 查看页面源代码,我看到了这些:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/jquery-ui.min.js"></script>
在我的 Web.config 我有这个:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />