【发布时间】:2013-08-31 15:54:54
【问题描述】:
我必须在单击按钮时重定向到控制器操作,但出现此错误
`A potentially dangerous Request.Path value was detected from the client (&).`
这是我的代码:
视图/_Layout.cshtml
<body>
<div id="wrapper">
<div id="tab1">
<div class="tab2">
<div id="test2" class="officebar">
<ul>
<li class="current"><a href="#" rel="home">Main</a>
<ul>
// ..other button code..
<li><span>Logout</span>
<div class="button">
<a href="#" id="Logout" title="Logout">
<div class="logout">
</div>
Logout</a>
</div>
</li></ul></li>
<script>
$("#Logout").click("click", function () {
//window.refresh("./Account/Logoutview");
// "@Url.Action("Logoutview", "Account")";
window.location = "@Url.Action("Logoutview", "Account")";
window.location.href = "@Url.Action("Logoutview", "Account")";
});
</script>
这是我的注销视图位置:
Views/Account/Logoutview
这是我的输出错误,请帮助:
编辑3:
如果我使用,我可以点击操作方法
<li>
<div><a class="button" href="@Url.Action("Logoutview", "Account")" title="Logout">Logout</a>
</div></li>
但我需要使用上面提到的设计。这是问题所在。
解决方案:我试过window.location.href = 'Account/Logoutview';而不是window.location.href = "@Url.Action("Logoutview", "Account")";
感谢用户 2110309、PKKG、MMohamad Bataineh 抽出宝贵时间 :)
【问题讨论】:
-
你能展示你的视图生成的源代码吗?我想看看你的那些 Url.Actions 的代码是怎么生成的?
-
检查我在问题中的编辑
-
您也可以为您的 LogOut 操作添加代码吗?
-
尝试使用
[ValidateInput(false)]作为您的操作方法。 -
@PKKG [ValidateInput(false)] 没有解决问题。 :(
标签: jquery asp.net-mvc buttonclick