Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC How to specify which folder the View pages reside in?

by default the ASP.NET MVC engine searches the following folders for View pages:

  • /Views/{Controller_Name}/{Action}.aspx
  • /Views/Shared/{Action}.aspx

However I want to put some of my View pages like this:

  • /Views/{Namespace}/{Controller_Name}/{Action}.aspx

How can I let the engine look for this?

like image 763
Ropstah Avatar asked Apr 28 '09 21:04

Ropstah


2 Answers

You can return view placed in custom sub-folders, from controller action by, giving out full view path in return statement,

ex.

public ActionResult Create() {     return View("~/Views/ProEnhance/Employee/Create.cshtml"); } 

here,

ProEnhance - user defined folder

Employee - Controller Name

Create - action Name

like image 198
Kailas Mane Avatar answered Sep 17 '22 12:09

Kailas Mane


You have to create a class derived from IViewEngine interface and register this class in Aplication_Start event in Global.asax.cs Check this link text, but there are some differences with 1.0

like image 27
Ofigenn Avatar answered Sep 19 '22 12:09

Ofigenn