MVC Page expansion method     The singleton pattern
 
 /// <summary>
        /// Create a Config content object
        /// </summary>
        /// <param name=""></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static MvcHtmlString ConfigSetting(this HtmlHelper helper, string key)
        {
            var str = ConfigHelper.GetValue(key);
            return MvcHtmlString.Create(str);
        }
call :@Html.ConfigSetting("contact-company-message")
 
public static class ConfigHelper
{
     static Dictionary<string,Configer> dic = null;
     static void InitClass()
     {
         if(dic == null)
          {
              using(var db = new Entities())
               {
                   dic = db.Configer.ToDictionary(r=>r.Key) 
               }
          }
     }
}
 
publicsh static void Refresh()
{
     usring(var db = new Entitiey())
          {
               dic = db.configer.ToDictory(r=>r.key);
          }
}
publist static string GetValut(string key)
{
     InitClass();
     if(!dic.keys.Contains(key))
          returnll;
     return dic[key].value;
}

MVC Page expansion method More articles on singleton patterns

  1. MVC Execute custom view with extended method , replace UIHint

    MVC Execute custom view with extended method , replace UIHint Used in the project Bootstrap , So you don't have to write too much CSS 了 , Save a lot of things . But this business system needs a lot of input , Every watch has 100 Multiple fields , Every page ...

  2. MVC ---- How to extend methods

    First, define an extension class : public static class StringExtend { // Expand one string Methods public static bool IsNullOrEmpty(this s ...

  3. Asp.net MVC Implementation of controller expansion method jsonp

    Project needs , In the use of KendoUI, It's about jsonp Data format processing , I can see such an implementation method on the Internet , Here's a little note ( In fact, it's because the company can only go to a few websites such as blog Garden , I'm afraid I forget , OK, check it out , Ha ha ha ) 1. New controller extension ...

  4. ASP.NET MVC It's persistent TempData And extension method ( 13、 ... and )

    Preface Before we started this series, we talked about MVC There are four ways to transfer data from controller to view in , But there is still a problem , This section talks about this problem and some exercises to see MVC Extension method in . topic of conversation No need to say more nonsense , We go straight into ...

  5. C# The compiler optimization thing c# If the value of an object is null, So why doesn't it report an error when it calls the extension method webAPI controller (Controller) Too much ? .NET MVC Project settings include Areas The page in is the default startup page ( 5、 ... and )Net Core Using static files Study ASP.NET Core Razor Programming Series 8 —— Concurrent processing

    C# The compiler optimization thing   Use C# Programming , Programs for end users , It is necessary to use release Configured , and release Configuration and debug To configure , There's a key difference , Namely release Compiler optimization for is enabled by default . Optimize the code ...

  6. ASP.Net MVC Develop basic learning notes : Two 、HtmlHelper And extension methods

    One . A powerful page development assistant class —HtmlHelper A preliminary understanding 1.1 There is a loss, there is a gain stay ASP.Net MVC Microsoft doesn't provide a development method similar to server-side control , After all, Microsoft's MVC It's the return of the traditional request processing response . ...

  7. ASP.NET MVC The expansion method of pre-school chapter 、 Chain programming

    ASP.NET MVC The expansion method of pre-school chapter . Chain programming Preface There is no other purpose , Is to introduce a few points in ASP.NETMVC be used C# Linguistic characteristics , There are other trivial points of knowledge , If you force a division , I can only say it's all about MVC of , yes , we have ...

  8. Fall in love with MVC~ by CheckBoxFor and RadioButtonFor Add an extension method ( hope MVC5 Put this method in —— ha-ha )

    Back to directory First of all I like to complicate things , And always like to simplify things , Laziness , This is also the pursuit of a programmer , ha-ha . I don't like repetition very much , When you see more than one of the same code on the page , It can be said that , Your code is refactored ...

  9. ASP.Net MVC Develop basic learning notes (2):HtmlHelper And extension methods

    One . A powerful page development assistant class —HtmlHelper A preliminary understanding 1.1 There is a loss, there is a gain stay ASP.Net MVC Microsoft doesn't provide a development method similar to server-side control , After all, Microsoft's MVC It's the return of the traditional request processing response . ...

Random recommendation

  1. JS actual combat &#183; Cascade menu to select province and city ( Two kinds of )

    DOM Programming steps . Ideas 1. Define the interface :       adopt html Tags encapsulate data : 2. Define some static styles :       utilize css: 3. Need to dynamically complete the interaction with the user :      a: Identify the source of the event :     ...

  2. HTML5 Audio and JavaScript Control

    IE8 The following is invalid <!DOCTYPE html> <html> <head> <meta content="text/html; charset=u ...

  3. nginx Configuration summary of

    Overall speaking ,nginx Compared with apache It's a lot simpler , It's much easier to understand , In addition, the documents on the official website are also very simple and easy to understand . Let's start with a simplified version of the configuration file nginx.conf: #user nobody; worke ...

  4. You understand these five questions javascript You'll get started

    1. if (!("a" in window)) { var a = 1; } alert(a); Reading the code : If window Does not contain attributes a, Just declare a variable a, Then it's assigned to 1, Finally, it pops up ...

  5. Achievement transformation AC Hang Dian

    Achievement transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. window And linux File sharing solutions

    My system is windows7 x64, Virtual machine linux System is centos6.5 Method 1 : 1. stay win7 Set up a user on the system 2. stay f Disk to create a folder linuxshare, Then right-click - attribute - share - Senior total ...

  7. linux Why shut down selinux

    General installation linux During the course, we all put SELinux And iptables Arranged in the back , Let beginners configure linux Server failed , But no clue , That's because of RedHat linux The firewall is turned on by default in the operating system ,SELinux also ...

  8. vue-cli,build after , The solution to reporting a mistake

    The error report is as follows : or : terms of settlement :config / index.js in , find build { assetsPublicPath: '/' }, Set it to :assetsPublicPath: './ ' ...

  9. NetCore Introduction :( Ten )Net Core Project use Cookies

    One . brief introduction 1.Net Core You can use it directly Cookies, But there are some differences in the way of calling . 2.Net Core take Request and Response Separate implementation . Two . Basic literacy Cookies operation 1. Write a basic reading and writing ...

  10. cocos2dx The pit of scene switching

    There is a class that can use different data sources , Each data source corresponds to an object . I keep instances of objects in the class , Because it's used in other places, it's static , And at each initialization To reset , Delete when destructing . Now I've opened A, Switch to B, It turns out that this static ...