c# - 为什么 Ajax.BeginForm 在提交后重定向到新的空页面?

标签 c# asp.net-mvc asp.net-ajax

为什么 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/

相关文章:

c# - 在 C# 中从 Outlook Express 发送电子邮件

c# - 使用图形与 WPF 应用程序连接到 Azure AD api

c# - asp.net如何判断Session是否过期

asp.net - asp.net MVC 中的用户登录

asp.net-mvc - 使用不显眼的验证处理占位符

jquery - 在 UpdatePanel 中使用 JQuery UI 日期选择器

javascript - 在 .NET 3.5 中将 ExtJS 与 Asp.net 和 WCF 一起使用的最佳实践是什么?

c# - 基于集合的动态 Datagrid 列

.net - 与asp.net mvc的dotnetopenauth证明太令人沮丧,无法使用

c# - 在删除项目后添加成功消息,在 MVC4 中