Nopcommerce 3.4 Mobile End-of-access abandon responsive layout

Source: Internet
Author: User
Tags nopcommerce

In the Nop3.4, he abandoned the original xxx.Mobile.cshtml this style, but adopted a responsive layout, and changed the rules, you configure in the background is not enabled responsive layout, in the foreground you still can not write xxx.Mobile.cshtml so. Check the reason for a day, and finally found out.

First of all, please understand the new features of Mvc4: http://www.cnblogs.com/egger/p/3400076.html

After reading this, it is estimated that you will also be misled, that MVC has already supported itself. Mobile.cshtml this notation. Think he must be where the set to disable, anyway, I just follow this way to find a morning without fruit. In the end, I traced his return View () method, and found that he did not use MVC's own method, but himself rewrite a set.

When you return to the view, He requested to Nop.Web.Framework this item in the Themeablevirtualpathproviderviewengine file in the Themes folder below, there are two methods in this file: Findview And Findpartialview, here, His approach in version 3.4 was to throw the controller directly into the Findthemeableview method and then look at the Findthemeableview method, and you'll find that in it, he would combine it with a controller and Aciton, and finally spell a NOP. The path to cshtml in.

For example, like this: Newlocations.insert (0, "~/administration/views/{1}/{0}.cshtml"); Not this code, don't move around here.

So, as long as Findview and Findpartialview pass over the controllername, you add your own rules, then he will generate the corresponding path.

Look at that findview inside.

Viewengineresult result = Findthemeableview (ControllerContext, ViewName, Mastername, UseCache);

It is obvious that he is in the path, as long as we are here, to change the viewname to Viewname.mobile will be finished.

The code is as follows:

1   /// <summary>2         ///to determine if the current request came from the phone.3         /// </summary>4         /// <param name= "HttpContext" >HTTP Context</param>5         /// <returns>Result</returns>6          Public Virtual BOOLIsMobileDevice (httpcontextbase HttpContext)7         {8             //Comment The code below if you want tablets to be recognized as mobile devices.9             //Nopcommerce uses the free edition of the 51degrees.mobi library for detecting browser mobile properties.Ten             //The By default this property (Istablet) is always false. You'll need the premium edition in order to get it supported.
     One             BOOLIstablet =false; A             if(BOOL. TryParse (httpcontext.request.browser["Istablet"], outIstablet) &&Istablet) -                 return false; -  the             if(HttpContext.Request.Browser.IsMobileDevice) -                 return true; -  -             return false; +}
IsMobileDevice
1 /// <summary>2         ///return to the view view3         /// </summary>4         /// <param name= "ControllerContext" ></param>5         /// <param name= "ViewName" ></param>6         /// <param name= "Mastername" ></param>7         /// <param name= "UseCache" ></param>8         /// <returns></returns>9          Public OverrideViewengineresult Findview (ControllerContext controllercontext,stringViewName,stringMastername,BOOLUseCache)Ten         { One             BOOLUsemobiledevice = IsMobileDevice (Controllercontext.httpcontext);//determine if the request is coming from the phone A             stringOverrideviewname = Usemobiledevice? -                 string. Format ("{0}. {1}", ViewName, _mobileviewmodifier) -: ViewName;//path _mobileviewmodifier This is a variable of type string, you can also directly write dead mobile or WAP, and so on, you are viewname._mobileviewmodifier.cshtml  theViewengineresult result = Findthemeableview (ControllerContext, Overrideviewname, Mastername, UseCache);//Find the View -             if(Usemobiledevice && (Result = =NULL|| Result. View = =NULL)) -result = Findthemeableview (ControllerContext, ViewName, Mastername, UseCache);//I didn't find it, and I tried to find it without a suffix. -             returnresult; +}
Findview
1  Public OverrideViewengineresult Findpartialview (ControllerContext controllercontext,stringPartialviewname,BOOLUseCache)2         {3             BOOLUsemobiledevice =IsMobileDevice (controllercontext.httpcontext);4             stringOverrideviewname = Usemobiledevice?5                 string. Format ("{0}. {1}", Partialviewname, _mobileviewmodifier)6 : Partialviewname;7Viewengineresult result =Findthemeablepartialview (ControllerContext, Overrideviewname, usecache);8             if(Usemobiledevice && (Result = =NULL|| Result. View = =NULL))9result =Findthemeablepartialview (ControllerContext, Partialviewname, usecache);Ten             returnresult; One}
Findpartialview

Nopcommerce 3.4 Mobile End-of-access abandon responsive layout

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.