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

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

4 Comments

Yes Bod, Area is registered.
In that case i suggest looking into this item: stackoverflow.com/questions/2624566/mvc-areas-view-not-found
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)
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: stackoverflow.com/a/23018523/7194432

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.