0
我正在使用C#asp.net mvc4并尝试执行ajax搜索。但它是错误的,它说“找不到资源”。 我做错了什么?ajax。无法找到资源
控制器
//Search
[HttpPost]
public ActionResult ContractSearch(string Name)
{
var contracts = db.Contracts.Include(c => c.DocType).Include(c => c.CreditType).Include(c => c.Bank).Include(c => c.UserProfile).Where(c => c.FirstName.Equals(Name));
return View(contracts.ToList());
}
查看
@model IEnumerable<CreditoriyaApp.Models.Contract>
@{
ViewBag.Title = "Index";
}
<div>
@using (Ajax.BeginForm("ContractSearch", "Contract", new AjaxOptions { UpdateTargetId = "searchresults" }))
{
<input type="text" name="Name" />
<input type="submit" value="Search" />
}
<div id="searchresults">
@if (Model != null && Model.Count()>0)
{
<ul>
@foreach (var item in Model)
{
<li>@item.FirstName</li>
}
</ul>
}
</div>
错误
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Contract/ContractSearch
是否'默认Ajax.BeginForm'使用GET请求而不是POST请求?控制器名称是否正确? – David
Ajax.BeginForm使用POST请求,控制器名称正确。 – tarakan
也许[这](http://stackoverflow.com/questions/4476511/asp-net-mvc-ajax-beginform-is-not-submitting-via-ajax)是你有同样的问题。干杯! –