为什么我的ASP.NET Action会查找错误的View?

qua*_*els 1 c# asp.net-mvc asp.net-mvc-2

我有一个简单的动作:

    public ActionResult CommentError(string error)
    {
        return View(error);
    }
Run Code Online (Sandbox Code Playgroud)

我有一个名为CommentError.ascx的简单局部视图:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>

<%: Model %>
Run Code Online (Sandbox Code Playgroud)

当我通过转到视图直接浏览到myurl.com/find/Comments/CommentError视图显示正常...没有错误.

但是,当我去myurl.com/find/Comments/CommentError?error=SomeErrorString,而不是绑定查询字符串string error,它寻找一个名为的视图SomeErrorString.ascx.

为什么会这样?

编辑
注意,我有一个自定义的global.asax,由我正在使用的路径指示(/ find/Comments/CommentError :::/find/{controler}/{action})

Cli*_*ity 6

如前所述,MVC正在寻找与string参数相同的视图.为避免这种情况,您需要将其强制转换为对象...

public ActionResult CommentError(string error)
{
    return View((object)error);
}
Run Code Online (Sandbox Code Playgroud)