Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC same view name, different paths

I want to have multiple path folder structure that contain same name views:

/profile.aspx
/admin/profile.aspx
/user/editpost.aspx
/admin/editpost.aspx

/Controllers
  |- PostController.cs
  |- ProfileController.cs

I want to be able to have all the regular pages in a folder and the admin pages in another folder. Do I need to organize my Views folder like:

/Views
  /User
    /Story
      |- editpost.aspx
    /Profile
      |- profile.aspx
  /Admin
    /Story
      |_ editpost.aspx
    /Web
      |- profile.aspx

or is there a way I can do this:

/User
  /Views
    /Story
      |- editpost.aspx
    /Profile
      |- profile.aspx
/Admin
  /Views
    /Story
      |_ editpost.aspx
    /Web
      |- profile.aspx

Also, how do I code/organize/use separate controllers for /User and /Admin that potentially have the same name?

Let me know if I have been unclear.

Thanks!

like image 653
john Avatar asked Jul 23 '09 04:07

john


2 Answers

No problem. You can organise your folders in any way you choose. You can specify a view by name or even by its path in the Action method:

return View("~/Views/Posts/Index.aspx");
like image 134
Tim Avatar answered Sep 26 '22 17:09

Tim


You should read this post by Phil Haack.

Basically, you're gonna have to create your own ViewEngine to work with your folder design.

like image 41
Çağdaş Tekin Avatar answered Sep 24 '22 17:09

Çağdaş Tekin