0

The Area controller is not hit. I have the following structure in ASP.MVC

--> Area
--> --> MyArea
--> --> --> Controllers
--> --> --> --> HomeController
--> --> --> Model
--> --> --> --> MyModel
--> --> --> Views
--> --> --> --> Home
--> --> --> --> --> Index
Controllers
--> HomeController
Views
--> Home
--> --> Index

When from root Controllers-HomeController "return View("~/Area/MyArea/Views/Home/Index.cshtml")" is called then Area-MyArea-Controllers-HomeController-Index Action is never hit! and hence Area-MyArea-Model-MyModel is always null in Area-MyArea-Views-Home-Index. Any suggestions

Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
PKK
  • 13
  • 6

1 Answers1

0

There is little information to work with. The only thing i can ask from this point is, have you registered your Area? Like this: http://www.c-sharpcorner.com/UploadFile/ansh06031982/areas-in-mvc-with-example/

Bob Meijwaard
  • 388
  • 9
  • 20
  • Yes Bod, Area is registered. – PKK Sep 17 '17 at 10:15
  • In that case i suggest looking into this item: https://stackoverflow.com/questions/2624566/mvc-areas-view-not-found – Bob Meijwaard Sep 17 '17 at 10:17
  • Nops, it does not solve the problem, If, let say we use return RedirectToAction("Index", "Home", new { Area = "MyArea" }), then controller index action is hit properly, but it also changes the browser URL to /MyArea/Home. What i am looking is return view("~/MyArea/Home/Index.cschmtl") along with controller action to be hit so that view (Index) in MyArea/Home can use model initialized in controller action. (With out changing browser URL) – PKK Sep 17 '17 at 10:38
  • Ok, i think i understand. MVC per default does not look in those Area folders when referring to Views. Last suggestion i am gonna make is adding additional View location for MVC to look in; this is done in this post: https://stackoverflow.com/a/23018523/7194432 – Bob Meijwaard Sep 17 '17 at 10:48