为什么 Ajax.BeginForm 在提交后将我的页面重定向到新的空页面?
我的 Controller 代码是:
[HttpPost]
public void ProductCommentAdd(int productId, string text)
{
//Do something
}
View 中的 Mvc ajax 调用是:
@using (Ajax.BeginForm("ProductCommentAdd", "Shop", new AjaxOptions() { HttpMethod = "POST"}))
{
<input type="hidden" value="@Model.ProductId" name="ProductId"/>
<textarea name="text"></textarea>
<input type="submit" value="Submit"
}
当我点击提交按钮时,我的页面重定向到新的空白页面。我该如何解决?
最佳答案
您需要在页面中包含以下脚本:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"
type="text/javascript"></script>
关于c# - 为什么 Ajax.BeginForm 在提交后重定向到新的空页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21787489/