0

我是 asp.net mvc 的新手。我的页面上有一个按钮。单击该按钮时,我只想显示下载对话框。我不想调用任何其他视图和控制器。每当我使用@Html.BeginForm("Index", "Download", FormMethod.Post)时,它都会打开新窗口以及下载对话框。我不想打开任何新窗口。我的代码如下

@Html.BeginForm("Index", "Download", FormMethod.Post)
                                {
                                @{if (check.CheckName != "Total")
                                  {
                                    <td colspan="2" align="right">
                                        <span class="button">
                                            <input type="submit" value="View Report" class="form_button" onclick="window.showModalDialog('/Download/Index?EmployeeID=@Model.EmployeeInformation.EmployeeID&RequestID=@Model.RequestInformation.RequestID','Download View','dialogHeight:4px;dialogWidth:4px;');" /></span>
                                    </td>
                                    <td colspan="2" align="left">
                                        <span class="button">
                                            <input type="submit" value="Download Report" class="form_button" /></span>
                                    </td>
                                  }
                                }

有没有办法做到这一点?

4

1 回答 1

1

您可以使用 Ajax.BeginForm 这可以使用表单内容仅更新页面的一部分,而无需打开新页面。

@using (Ajax.BeginForm("Index", "Download", new AjaxOptions
                    {
                        HttpMethod = "GET",
                        UpdateTargetId = "area", // the div that will have your form contents
                        InsertionMode = InsertionMode.Replace                          
                    }))
{
   // here you can put your form content normally like the 'Html.BeginForm'
}

<div id = "area">
</div>

并使您的 Action 返回 PartialView。

于 2013-06-03T08:33:08.333 回答