views:

923

answers:

4

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.

A: 

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

brian b
Yeah it was suppose to be forumextention.forumdata .. but I was the error that I posted here was just for explaination of my problem.
dswatik
A: 

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

Charlino
Same thing I tried that when I discovered it didn't like the view being where I had it... strange thing is it can be anywhere just as long as its under the Views folder... I just don't get it.. its a totally wierd problem.
dswatik
A: 

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?

Joe
Did you use a strongly typed view? the ViewData["forums"] method works fine..I'll post what I was trying to do exactly.
dswatik
+3  A: 

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

maartenba
Link is incomplete
David Gardiner