Ajax表单不是未提交给控制器操作。我一直试图解决这个问题超过一个小时。下面是代码未提交给控制器操作的Ajax表格
@using (Ajax.BeginForm("searchCustomers", "Transaction", new { phoneNumber = Model.CustomerMobile }, new AjaxOptions
{
UpdateTargetId = "custList",
InsertionMode = InsertionMode.Replace
}))
{
<div class="col-md-6">
<div class="form-group">
<label>Customer Mobile No:</label>
@Html.TextBoxFor(x => x.CustomerMobile, new { @class = "form-control", id = "custMobile" })
</div>
@*<div class="form-group">
<label>Customer Name</label>
@Html.TextBoxFor(x => x.CustomerName, new { @class = "form-control", id = "custName" })
</div>*@
<input type="submit" class="btn btn-default" value="Get Customer Details" >
</div>
}
这里是控制器动作
public ActionResult searchCustomers(string phoneNumber)
{
if (phoneNumber==null)
{
return PartialView(new List<Models.Customer>());
}
var c = Database.Session.Query<Models.Customer>()
.Where(x => x.MobileNumber.Like(phoneNumber))
.ToList();
return PartialView(c);
}
但Ajax表单不提交。我已经将java脚本文件添加为捆绑包。我有另一个@Html.Action("searchCustomers", new { phoneNumber = Model.CustomerMobile })
这个叫做控制器动作。 请询问更多详情。 任何人都可以告诉它为什么不起作用。任何帮助将不胜感激。提前致谢。
custList元素是否存在于您的DOM中?只是为了确保,你的控制器被称为交易,你确实有适当的路线设置,对吗? – Guga
是的,有一个custList元素和控制器名称是正确的 – Sony