本文介绍了为什么我的ASP.NET行动寻找错误的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的动作:

    public ActionResult CommentError(string error)
    {
        return View(error);
    }

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

I have a simple partial view called CommentError.ascx:

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

<%: Model %>

当我浏览到视图directy转到 myurl.com/find/Comments/CommentError 视图显示细腻......没有错误。

When I browse to the view directy by going to myurl.com/find/Comments/CommentError the view displays fine... no errors.

但是,当我去 myurl.com/find/Comments/CommentError?error=SomeErrorString ,而不是查询字符串结合字符串错误,它会寻找一个名为视图 SomeErrorString.ascx

But, when I go to myurl.com/find/Comments/CommentError?error=SomeErrorString, instead of binding the querystring to string error, it looks for a view called SomeErrorString.ascx.

为什么会出现这种情况?

Why is this happening?

修改
请注意,我有一个自定义的Global.asax由我使用的路径指示(/发现/评论/ CommentError ::: /发现/ {} CONTROLER / {}动作)

Edit
Note, i do have a custom global.asax as indicated by the paths I'm using (/find/Comments/CommentError ::: /find/{controler}/{action})

推荐答案

如前所述,MVC正在寻找一个名为一样的字符串参数视图。为了避免这种情况,您需要将其转换为一个对象...

As mentioned, MVC is looking for a view named the same as the string parameter. To avoid this, you need to cast it to an object...

public ActionResult CommentError(string error)
{
    return View((object)error);
}

这篇关于为什么我的ASP.NET行动寻找错误的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:20