Saturday, 17 February 2018

Custom view engine in mvc

using Nop.Web.Framework.Themes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Plugin.Help.Desk.ViewEngines
{
    public class CustomViewEngine : ThemeableRazorViewEngine
    {
        public CustomViewEngine()
        {
            PartialViewLocationFormats =
            new[]
            {
                    "~/Plugins/Help.Desk/Views/{0}.cshtml",
                      "~/Plugins/Help.Desk/Views/Shared/{0}.cshtml",
                       "~/Plugins/Help.Desk/Views/Shared/EditorTemplates/{0}.cshtml",
            };

            ViewLocationFormats =
                new[]
                {
                    "~/Plugins/Help.Desk/Views/{0}.cshtml",
                      "~/Plugins/Help.Desk/Views/Shared/{0}.cshtml",
                       "~/Plugins/Help.Desk/Views/Shared/EditorTemplates/{0}.cshtml",
                };
        }
    }
}

Register CustomViewEngine class inglobal.asax file-

protected void Application_Start()
{

  ViewEngines.Engines.Clear();

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

}

No comments:

Post a Comment