ASP.NET AjaxActionLink请求中的潜在危险Request.Path

时间:2015-06-11 14:48:30

标签: c# asp.net-mvc razor

我在MVC ASP.NET应用程序中有一个cshtml视图。我想简单地允许用户在执行操作之前单击按钮并向用户提供警告。我知道实现我想要的唯一方法是使用像这样的AjaxActionLink

<a role="button" 
   class="btn btn-lg btn-primary" 
   href='@Ajax.ActionLink(
        "Clear Invite Log",
        "ClearInviteLog",
        "Tools",
        null,
        new AjaxOptions { HttpMethod = "GET" },
        new { onclick = "return confirm('Are you sure you want to clear the invite log?');" })'>
    Clear Invite Log
</a>

我的控制器名称为ToolsController,我发布的方法为ClearInviteLog。问题是当我点击按钮时我没有得到警告对话框,而是我得到了

  '/'应用程序中的服务器错误。   从客户端(&lt;)检测到潜在危险的Request.Path值。

     

堆栈跟踪:   [HttpException(0x80004005):从客户端(&lt;)检测到一个潜在危险的Request.Path值。]      System.Web.HttpRequest.ValidateInputIfRequiredByConfig()+9693412      System.Web.PipelineStepManager.ValidateHelper(HttpContext context)+53

我是网络开发的新手,我很困惑。我在这里做错了什么?

感谢您的时间。

1 个答案:

答案 0 :(得分:2)

您不需要设置锚标记href值的Ajax.ActionLink,Ajax.ActionLink和Html.ActionLink本身将渲染为锚标记,您只需直接使用Ajax.ActilnLink

@Ajax.ActionLink(
    "Clear Invite Log",
    "ClearInviteLog",
    "Tools",
    null,
    new AjaxOptions { HttpMethod = "GET" },
    new 
       { 
         onclick = "return confirm('Are you sure you want to clear the invite log?');",
         @class ="btn btn-lg btn-primary",
         role="button" })