Using MEF for pluggable architecture in MVC

Ok i have a strange problem that i hope someone can help with

I have an MVC project based on this demo

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

However, when setting 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 traced it before this happened, when you indicate the path to the view like this:

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

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

  return View(data); 

so why does it matter, it is obvious that this is due to the way the viewing engine works, and the fact that the controller is actually external to the application ... Help please!

Edit:. ForumData is actually ForumExtention.ForumData, I was wrong when I generated an error to cut and paste, but it does the same no matter what .. I just needed to get the point through ..

Update: The sample in the link I provided works fine because it does not use a strongly typed view ... Check the actual code I played with by downloading it here

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

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

Rename foumdb.zip to * .bak this is a backup of the SQLEXPRESS 2008 database.

+4
source share
4 answers

I found why, but these classes are not connected in ASP.NET.

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

+3
source

Is ForumData in an accessible namespace? Do I need to qualify a name?

0
source

I don’t know anything about MEF ... but what happens if you create your own slightly modified view mechanism to look in different directories?

eg.

 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

0
source

I upload your sample. I moved the forum index in utils to the main web application. It worked fine.

 public ActionResult Index() { ViewData["forums"] = _forumService.GetEnabledForumsRecentActivity(); return View("~/Utils/Index.aspx"); // return View(ViewRoot + "Index.aspx"); } 

In what specific places did you place it in the sample catalogs?

0
source

Source: https://habr.com/ru/post/1286138/


All Articles