我有一个简单的 Action :
public ActionResult CommentError(string error)
{
return View(error);
}
我有一个名为 CommentError.ascx 的简单局部 View :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>
<%: Model %>
当我通过转到 myurl.com/find/Comments/CommentError
浏览到 View 目录时, View 显示正常...没有错误。
但是,当我转到 myurl.com/find/Comments/CommentError?error=SomeErrorString
时,它没有将查询字符串绑定(bind)到 string error
,而是寻找一个名为 SomeErrorString.ascx
的 View 。
为什么会这样?
编辑
请注意,我确实有一个自定义的 global.asax,如我正在使用的路径所示(/find/Comments/CommentError:::/find/{controler}/{ Action })
最佳答案
如前所述,MVC 正在寻找与字符串参数同名的 View 。为避免这种情况,您需要将其转换为一个对象...
public ActionResult CommentError(string error)
{
return View((object)error);
}
关于c# - 为什么我的 ASP.NET 操作寻找错误的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4522409/