部分页面回发在asp.net MVC 5中不起作用

时间:2014-04-17 06:48:25

标签: asp.net asp.net-mvc asp.net-mvc-4

我有一个asp.net MVC 5视图。我在其中有以下标记(以及其他一些html控件)

 @using (Html.BeginForm("SendReport", "Poll", System.Web.Mvc.FormMethod.Post, new { id= "frmSendReport"}))
                        {
                        <div id="descSection">
                            <textarea id="Description" placeholder="" cols="65" rows="5" style="width:420px;"></textarea>  <br />
                            <input id="create-poll-button" class="btn" type="submit" value="Send" />
                        </div>
                        }





 $("#frmSendReport").submit(function () {         
            $("#section1-saving").html("<img src='../../../Images/loading.gif' />");
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    alert(result);
                    $("#section1-saving").html("Report sent!");
                    $.ajaxSettings.cache = false;

                    // Refresh the sub section 2 on the Section 2 tab
                    //$("#descSection").html('I am here');
                },
                error: function (jqXHR, textStatus, errorThrown) {                   
                    $("#section1-saving").html("Error: " + textStatus + " " + errorThrown);
                }
            });
            return false;
        });

我的控制器动作是这样的:

 [HttpPost]
        public ActionResult SendReport(FormCollection frm)
        {
            string name = User.Identity.Name;         
            return Json(name );

        }

[EDITED]

  @using (Ajax.BeginForm("SendReport", "Poll", new AjaxOptions
    {
        InsertionMode = InsertionMode.Replace, 
        HttpMethod = "POST",
        OnSuccess = "alert('done');"
    }, new { @id = "updateCarForm" }))
 {
                        <div id="descSection">
                            <textarea id="Description" placeholder="" cols="65" rows="5" style="width:420px;"></textarea>  <br />
                            <input id="create-poll-button" class="btn" type="submit" value="Send" />
                        </div>
                        }

我看到当我点击“发送”按钮时,表单会刷新而不是部分回发。请建议如何解决它。

0 个答案:

没有答案