【发布时间】:2019-05-10 15:06:39
【问题描述】:
我在 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>
【问题讨论】:
-
你尝试过使用 JQuery 并在成功函数中替换 Html 吗?
-
您可以使用此网址stackoverflow.com/questions/4730777/…将部分视图作为字符串返回
-
我不需要转换成字符串
-
当它作为字符串返回时,您可以使用 html 字符串到 html -replace div - $("container selector").html(returned html);
-
您的页面中是否包含
jquery.unobtrusive-ajax.jsjavascript 文件?如果您看到的是普通表单提交而不是 ajax,这意味着所需的脚本未正确加载。检查您的浏览器控制台,看看您是否在那里看到任何错误。
标签: ajax asp.net-mvc