我检查了重复的线程,但没有工作。我点击关闭后只需要关闭浏览器。但它正在触发Controller [HttpPost]方法而不是关闭浏览器。
如果从另一个窗口打开相同的网址,浏览器正在关闭。
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
.....
....
<td align="right">
<input type="submit" name="btnSave" value="Save" id="btnSave" />
<input type="submit" name="btnCancel" value="Cancel" id="btnCancel" />
</td>
}
<script type="text/javascript">
$(document).ready(function () {
......
$("#btnCancel").click(function (event) { window.close(); });
});
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(List<CustomerCommPreferences> lstcustCommPref, bool chkSolicitation)
{
}
控制台警告显示Scripts may not close windows that were not opened by script.
答案 0 :(得分:1)
JavaScript只能关闭它打开的窗口。例如:
yourWindow.close();
然后您可以使用HTML
您击中控制器的原因是因为您有两个位于var splitSearch = JSON.parse("{\""+(location.search.substr(1).replace(/\=/g,"\"\:\"").replace(/\&|(\/\?)/g,"\", \""))+"\"}")
形式内的按钮。单击这些按钮后,表单将提交回服务器。