我在Ajax和ASP.NET MVC中遇到问题。当我单击提交按钮时,我重定向到部分页面。我不需要重定向-我需要替换div
控制器
public PartialViewResult ajaxtest(string prname)
{
var aj = db.acount.Where(p => p.name.StartsWith(prname));
return PartialView("_ajTest", aj.ToList());
}
查看
@using (Ajax.BeginForm("ajaxtest", "Default1", new AjaxOptions () {
HttpMethod = "POST",
UpdateTargetId = "othmanN",
InsertionMode = InsertionMode.Replace
}))
{
<label>Product Name :</label>
@Html.TextBox("prname")
<input type="submit" name="name" value="search" />
}
<div id="othmanN">
//here table
</div>
答案 0 :(得分:0)
您的代码很好,只需要导入jquery.unobrusive-ajax.js
jquery导入后导入
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
如果您没有安装lib,请在这里: https://www.nuget.org/packages/Microsoft.jQuery.Unobtrusive.Ajax/