First, you need an abstract class webviewpage that inherits the webviewpage <t>
Example
Namespace loyalty. memberportal. Web. helpers
{
Public abstract class webviewpage <tModel>: system. Web. MVC. webviewpage <tModel>
{
// Delegate. If necessary, an ihtmlstring is returned.
Public Delegate ihtmlstringlocalizer (string key, string range );
Private localizer _ localizer;
Public localizer t
{
Get
{
Return (key, range) =>
{
// This section is logical. Here is the code for implementing localization. With httpruntime cache, you can write your own code.
VaR _ cachemanager = new memorycachemanager ();
List <fakeresourcetable> homepage = _ cachemanager. Get (range, () =>
{
VaR _ mamagelocalization = new managelocalization ();
Return _ mamagelocalization. gethome ();
});
VaR languageinstance = httpcontext. Current. Request. Cookies ["languagecode"];
VaR languagecode = languageinstance = NULL? 0: languageinstance. value. transfer=agecodetoid ();
VaR value = homepage. Where (M => M. Key = Key & M. languageid = languagecode). firstordefault (). value;
Return new htmlstring (value );
};
}
}
Public override void inithelpers ()
{
Base. inithelpers ();
}
Public override string Layout
{
Get
{
VaR layout = base. layout;
Return layout;
}
Set
{
Base. layout = value;
}
}
}
// Required, which is a required element of webviewpage
Public abstract class webviewpage: webviewpage <dynamic>
{
}
}
The next important step is to add the secondary engine to the Web. config file. This web. config is in view, not the one in the project.
<System. Web. webpages. Razor>
<Host factorytype = "system. Web. MVC. mvcwebrazorhostfactory, system. Web. MVC, version = 5.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
// Original, default
<! -- <Pages pagebasetype = "system. Web. MVC. webviewpage"> -->
<Pages pagebasetype = "loyalty. memberportal. Web. helpers. webviewpage">
<Namespaces>
<Add namespace = "system. Web. MVC"/>
<Add namespace = "system. Web. MVC. Ajax"/>
<Add namespace = "system. Web. MVC. html"/>
<Add namespace = "system. Web. Routing"/>
</Namespaces>
</Pages>
</System. Web. webpages. Razor>
Then we can call it in our view.
@ T ("joinnow", "Homepage") // The parameter corresponds to the T (a, B) method parameter.
Custom razor engine, custom tag, just like @ T ("key") in nopcommerce to implement multi-Mandarin