0

I am trying to create two MVC applications, and in first application created one view and compiled the application, and in the second application i have added the dll of the first application. in the routeconfig.cs file added the below line.

"Structure of First application"

Application1

 Controller
       Home(Actionmethod is Home)
       View
         Home.cshtml

 Application2: references:Application1

_layout.cshtml.

trying to access url: localhost/Home

routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        namespaces: new[] { "TestApp.Controllers" }

and i am trying to call the view from the first application, but it is not able to find the view from the first application, can any body tell me any other configurations do i need to add to access the view of first application.

Thanks in advance.

Chiranjeevi
  • 161
  • 1
  • 4
  • 22

2 Answers2

0

Please explain why you have them in two separate mvc applications.

app 1.
   controller
   view
   model
app 2. 
   controller
   view
   model

Im not sure if view are compiled into the .dll if they are. Then how are you accessing them?

Also you need to register your search locations for your views... I assume your are using the razor engine.

http://theshravan.net/blog/configure-the-views-search-locations-in-asp-net-mvc/

Can I specify a custom location to "search for views" in ASP.NET MVC?

Basically you need to register the search locations for your views the default is

App
   Views
      [ViewName]Controller

I have a strong feeling the app which references the .dll [App1] Has nothing in it to tell it to look in App2 for views as well.

Hope this makes sense ;-)

Community
  • 1
  • 1
Seabizkit
  • 2,417
  • 2
  • 15
  • 32
  • :I am not sure, i gone through the existing application, and what i understood from this is , in the second application they have the lay out and from the first application i have to access view. All views(pages) will be from first application and only in the second application background things will be there, i am sorry if i am not using the right terminology, just i started working with MVC. and true in both applications it is razor view engine used. – Chiranjeevi Sep 20 '15 at 15:44
  • if you are new to MVC then why use two Apps? Just use one until you more OK with splitting apps. For poeple to better answer you, it would make sense to explain why there are two apps. Just have one MVC App... anyway I am sure your problem is that your view locations are not regesteded..... You have access to your Controllers through the .Dll but how are you wiring it up. I can see that the routing you did may be right/or not but its still does not handle the view. Please post structure of your apps. and then which one references the dll... or are you including the Project in other Solution. – Seabizkit Sep 20 '15 at 15:49
  • I don't have chance to go, some body started and left there, and doing R&D from there it self, no go. let me go through your suggested articles.Thank you, let me add more code – Chiranjeevi Sep 20 '15 at 15:53
  • Those links i gave should help.... they explain how to setup custom view locations..., which if you have two apps then there should be two different view sources.... unless im missing something. – Seabizkit Sep 20 '15 at 15:56
0

Try creating Area in your project and create required controller and views instead of accessing view of another project.

Amar
  • 407
  • 1
  • 5
  • 24