ASP.Net MVC View Architecture

Can folders in a view have subfolders? if so, how does the Controller reach them? For example ... I would like the following URLs to work correctly:

  • Admin / Index
  • Admin / Profile / Index
  • Admin / Profile / Edit / 1
  • Admin / Group / Index
  • Admin / Group / Edit / 1

So, would I create a folder for the profile and group as a subfolder inside Admin?

I tried this and matched the route in the global file, but this does not seem to work.

+3
source share
4 answers

, , , . , . :

RedirectToAction ,

  • Admin/Index
  • /
  • /

  • /Index
  • //1
  • Group/Index
  • //1

[Authorize(Roles = "Administrator")] [AcceptVerbs(HttpVerbs.Post)] //

+4

return :

return View("Profile/Index");

, "subview". URL- , subview, .

+3

ViewEngine , ,

public class MyViewEngine : WebFormViewEngine
{
    public MyViewEngine()
    {
        ViewLocationFormats = new[] { 
            "~/{0}.aspx",
            "~/{0}.ascx",
            "~/Views/{1}/{0}.aspx",
            "~/Views/{1}/{0}.ascx",
            "~/Views/Shared/{0}.aspx",
            "~/Views/Shared/{0}.ascx",
        };

        MasterLocationFormats = new[] {
            "~/{0}.master",
            "~/Shared/{0}.master",
            "~/Views/{1}/{0}.master",
            "~/Views/Shared/{0}.master",
        };
        PartialViewLocationFormats = ViewLocationFormats;

    }
}

ViewEngines.Engines.Add(new MyViewEngine());
+3

, , :

MVC ""

, , , ViewEngine , , .

+1

Source: https://habr.com/ru/post/1702989/


All Articles