3

I made a project where I have a basic DemoController:

<Export(GetType(IController))> _
<ExportMetadata("controllerName", "Demo")> _
<PartCreationPolicy(CreationPolicy.NonShared)> _
Public Class DemoController Inherits Controller

    Public Function Index() As ActionResult
        Return View("~/Views/Demo/Index.aspx")
    End Function

End Class

In my "plugin" project that has this controller, it has the path /View/Demo/Index.aspx. When I run my main web app, I can get to the return View line but then it says the file cannot be found.

Why would this be?

I hope this all makes sense and sorry for the poor formatting.

I should probably mention that my .aspx file is in another project than the web app. I build everything into a dll then put that into a folder in my web app project. The error I am getting is "The view '~/Views/Demo/Index.aspx' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Demo/Index.aspx"

gblock
  • 790
  • 4
  • 11
  • 25

3 Answers3

2

you must register the views for your plugins

the flow with asp.net mvc flow asp.net mvc

so if you're developing plugins with DI you must keep in mind a few things -custom View Engine -custom Controller Factory

the default ControllerFactory can't resolve the controllers of your plug-ins, it's the same with the viewEngine, you must tell to the viewEngine where is that view

here is a example http://blog.maartenballiauw.be/post/2008/05/20/Creating-a-custom-ViewEngine-for-the-ASPNET-MVC-framework.aspx

Zach dev
  • 1,610
  • 8
  • 15
2

You said that you have all the views embedded in a separate project. Using the built-in view engine won't work. Either you have to specify the view locations in the built-in view engine as specified in this thread or create a custom view engine.

Community
  • 1
  • 1
VJAI
  • 32,167
  • 23
  • 102
  • 164
1
~/Demo/Index

Should be right route

Also, please fix the return like that

Return View()

or

Return View("Index")
AD.Net
  • 13,352
  • 2
  • 28
  • 47
  • Still doesn't work. This is the error I'm getting: The view '~/Demo/Index.aspx' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Demo/Index.aspx – gblock Jun 13 '12 at 19:10
  • You'll have to have the default structure of the solution. Example: you'll need the folder "Views" under which there should be a folder for each controller, which should contain your pages according to actions, Index action should have Index.aspx page. Also, make sure you're correctly deploying it as a mvc application. – AD.Net Jun 13 '12 at 19:35
  • Still doesn't work. It's looking for the view in my web app project, and the view is in my plugin project. They are both in the same solution. The plugin solution has the path ~/Views/Demo/Index.aspx and the controller is called DemoController. The website I'm looking at is this, except I am doing it in VB and I had to change the CreateController method in MefControllerFactory method. http://blog.maartenballiauw.be/post/2009/04/21/ASPNET-MVC-and-the-Managed-Extensibility-Framework-%28MEF%29.aspx – gblock Jun 13 '12 at 19:40
  • One of my projects is a class library and the other is a MVC 3 app if that makes a difference. – gblock Jun 13 '12 at 19:54
  • you must register the views on the ViewEngine, did you registered the views of plugin? – Zach dev Jun 13 '12 at 19:55
  • I don't think I did. How do you do that? – gblock Jun 13 '12 at 19:56