使用MVC打开一个新窗口

Aar*_*zar 3 javascript c# asp.net asp.net-mvc

基本上我想要一个按钮,在包含我的http://fake.com/Report/PageFixes...页面的新窗口中打开一个页面.目前我在一个表单中有一个按钮,但如果有更好的方法,那么我也是这样做的.

<% using (Html.BeginForm("PageFixes", "Report", new { id = 9 }, FormMethod.Get, new { onSubmit="window.open()" })) %>
<% { %>
    <%= Html.CSButton(new ButtonViewData() { Text = "Submit" })%>
<% } %>
Run Code Online (Sandbox Code Playgroud)

Kel*_*sey 6

你不需要一个form.只需将以下HTML添加到您的视图中:

<button type="button" onclick="window.open('<%= Url.Action("PageFixes", "Report", new { id = "9" } ) %>', '_blank'); return false;">submit</button>
Run Code Online (Sandbox Code Playgroud)

我不确定你是如何获得的9,ID但我认为它来自你的模型,所以你可以替换"9"使用Model.ID或其他东西.

关键是生成url,Url.Action然后只使用基本的javascript函数window.open在新的浏览器窗口中打开url.