How to change default view location scheme in ASP.NET MVC?

前端 未结 5 477
甜味超标
甜味超标 2020-11-27 02:45

I want to change view locations at runtime based on current UI culture. How can I achieve this with default Web Form view engine?

Basically I want to know how implem

5条回答
  •  面向向阳花
    2020-11-27 03:23

    I believe that solution would be to create your own ViewEngine which inherits from WebFormViewEngine. In constructor, it should check current UI culture from current thread and add appropriate locations. Just don't forget to add it to your view engines.

    This should look something like this:

    public class ViewEngine : WebFormViewEngine
    {
        public ViewEngine()
        {
            if (CultureIsX())
                ViewLocationFormats = new string[]{"route1/controller.aspx"};
            if (CultureIsY())
                ViewLocationFormats = new string[]{"route2/controller.aspx"};
        }
    }
    

    in global.asax:

    ViewEngines.Engines.Add(new ViewEngine());
    

提交回复
热议问题