在 MVC 中使用 MEF 实现可插拔架构
好吧,我遇到了一个奇怪的问题,我希望有人可以帮助
我,我有一个基于此演示的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了原因,但是 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
ForumData 位于可访问的命名空间中? 名字需要限定吗?
ForumData is in an accessible namespace? Does the name need to be qualified?
我对 MEF 一无所知...但是如果您创建自己的稍微调整的视图引擎来查看不同的目录,会发生什么?
例如,
中的 Application_Start() 中
然后在您的 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.
Then in Application_Start() in your global.asax
HTHs,
Charles
我下载你的样本。 我将论坛索引移至主网络应用程序中的 utils。 效果很好。
您将其放置在示例目录中的哪些具体位置?
I download your sample. I moved the forum index to utils in the main web app. it worked fine.
Which specific places did you place it at in the sample's directories?