在 MVC 中使用 MEF 实现可插拔架构

发布于 2024-07-24 09:05:42 字数 1421 浏览 8 评论 0原文

好吧,我遇到了一个奇怪的问题,我希望有人可以帮助

我,我有一个基于此演示的 MVC 项目

http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample。 aspx

但是,在指定强类型视图时它有问题我收到此错误

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<ForumData>'.

我跟踪到它必须与当您指定视图的路径时一样,

 return View("~/Modules/Forums/Index.aspx",data);

它会给您该错误,但如果您将视图在正常路径下,在本例中为“~Views/Forum/Index.aspx ....当指定返回时它工作得很好,

 return View(data);

所以为什么这很重要,这显然与视图引擎的工作方式有关,并且事实上,控制器实际上是应用程序外部的...请帮助

编辑: ForumData 实际上是 ForumExtention.ForumData,当我生成剪切和粘贴错误时我犯了一个错误,但确实如此!无论如何,都是一样的..我只需要了解要点..

更新:我提供的链接中的示例工作正常,那是因为它没有使用强类型视图...查看我正在使用的实际代码是从这里下载的

http://mysql.netpmg.com/MVCandMEF。 zip

http://mysql.netpmg.com/forumdb.zip

重命名foumdb.zip 到 *.bak,它是 SQLEXPRESS 2008 DB 备份。

Ok I got a strange issue that I hope someone could help with

I have a MVC project based upon this demo

http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx

However it has a problem when specifying a strongly typed view I get this error

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<ForumData>'.

I tracked it down to it having to with when you specify the path to the view like so

 return View("~/Modules/Forums/Index.aspx",data);

it gives you that error but if you put the view under the normal path which in this case would be "~Views/Forum/Index.aspx .... it works fine when specifying the return like so

 return View(data);

so why would it matter it obviously is something to with the way the view engine works and the fact that the controller is actually external to the application...Help please!

Edit: The ForumData is actually ForumExtention.ForumData, I made a mistake when I generated the error to cut and paste but it does the same thing no matter what.. I just needed to get the point accross..

Update: The sample in the link I provided works fine thats because its not using a strongly typed view...Check out the actual code I was playing with by downloading it from here

http://mysql.netpmg.com/MVCandMEF.zip

http://mysql.netpmg.com/forumdb.zip

Rename the foumdb.zip to *.bak it's a SQLEXPRESS 2008 DB backup.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

再浓的妆也掩不了殇 2024-07-31 09:05:42

我找到了原因,但是 ASP.NET 中的那些类是不可插入的。

肮脏的解决方法可以在我的博客上找到:Revised: ASP.NET MVC and the Managed Extensibility Framework (MEF) - http://blog.maartenballiauw.be/post/2009/06/17/Revised-ASPNET-MVC- and-the-Managed-Extensibility-Framework-(MEF).aspx

I found why, but those classes in ASP.NET are not pluggable.

Dirty workaround can be found on my blog: Revised: ASP.NET MVC and the Managed Extensibility Framework (MEF) - http://blog.maartenballiauw.be/post/2009/06/17/Revised-ASPNET-MVC-and-the-Managed-Extensibility-Framework-(MEF).aspx

年少掌心 2024-07-31 09:05:42

ForumData 位于可访问的命名空间中? 名字需要限定吗?

ForumData is in an accessible namespace? Does the name need to be qualified?

删除会话 2024-07-31 09:05:42

我对 MEF 一无所知...但是如果您创建自己的稍微调整的视图引擎来查看不同的目录,会发生什么?

例如,

public class CustomViewEngine : WebFormViewEngine
{

    public CustomViewEngine()
    {
        MasterLocationFormats = new[] {
                "~/Modules/{1}/{0}.master",
                "~/Views/{1}/{0}.master",
                "~/Views/Shared/{0}.master"
            };
        ViewLocationFormats = new[] {
                "~/Modules/{1}/{0}.aspx",
                "~/Modules/{1}/{0}.ascx",
                "~/Views/{1}/{0}.aspx",
                "~/Views/{1}/{0}.ascx",
                "~/Views/Shared/{0}.aspx",
                "~/Views/Shared/{0}.ascx"
            };
        PartialViewLocationFormats = ViewLocationFormats;
    }

}

中的 Application_Start() 中

ViewEngines.Engines.Add(new CustomViewEngine());

然后在您的 global.asax HTH ,
查尔斯

I don't know anything about MEF... but what happens if you create your own slightly tweaked view engine to look in a different directories?

E.g.

public class CustomViewEngine : WebFormViewEngine
{

    public CustomViewEngine()
    {
        MasterLocationFormats = new[] {
                "~/Modules/{1}/{0}.master",
                "~/Views/{1}/{0}.master",
                "~/Views/Shared/{0}.master"
            };
        ViewLocationFormats = new[] {
                "~/Modules/{1}/{0}.aspx",
                "~/Modules/{1}/{0}.ascx",
                "~/Views/{1}/{0}.aspx",
                "~/Views/{1}/{0}.ascx",
                "~/Views/Shared/{0}.aspx",
                "~/Views/Shared/{0}.ascx"
            };
        PartialViewLocationFormats = ViewLocationFormats;
    }

}

Then in Application_Start() in your global.asax

ViewEngines.Engines.Add(new CustomViewEngine());

HTHs,
Charles

小霸王臭丫头 2024-07-31 09:05:42

我下载你的样本。 我将论坛索引移至主网络应用程序中的 utils。 效果很好。

public ActionResult Index()
        {
            ViewData["forums"] = _forumService.GetEnabledForumsRecentActivity();

            return View("~/Utils/Index.aspx");
           // return View(ViewRoot + "Index.aspx");
        }

您将其放置在示例目录中的哪些具体位置?

I download your sample. I moved the forum index to utils in the main web app. it worked fine.

public ActionResult Index()
        {
            ViewData["forums"] = _forumService.GetEnabledForumsRecentActivity();

            return View("~/Utils/Index.aspx");
           // return View(ViewRoot + "Index.aspx");
        }

Which specific places did you place it at in the sample's directories?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文