The recent Taghelper project to upgrade from the original ASP. NET 5 beta 4 to beta 5, specifically organized the changes after the upgrade:
- New Imagetaghelper
- Tag Helper supports binding dictionary properties
Now you can bind the server-side attributes to the dictionary property in Taghelpers. For example, Anchortaghelper uses the name format of the asp-route-* attributes to set the route value.
<a asp-action= "Edit" asp-route-id= "@index" >Edit</a>
In this class, define the following:
public class anchortaghelper:taghelper{ Private Const string routevaluesdictionaryname = "Asp-all-route-data"; Private Const string Routevaluesprefix = "asp-route-"; <summary>// Additional parameters for the route. </summary> [Htmlattributename (routevaluesdictionaryname, Dictionaryattributeprefix = Routevaluesprefix)] public idictionary<string, string> routevalues {get; set;} = new dictionary< String, string> (stringcomparer.ordinalignorecase); ... }
Only the definitions related to the dictionary attribute are listed here, mainly by adding Htmlattributename to the property header and setting its dictionaryattributeprefix.
- Tag Helper supports conditional bindings based on the server-side attributes settings and supports wildcard *.
You can use the Attributes property in Targetelementattribute to specify that the current taghelper be applied to tags that have some attributes. For example, the Anchortaghelper class is defined as follows:
[Targetelement ("a", Attributes = Actionattributename)] [Targetelement ("a", Attributes = Controllerattributename)] [Targetelement ("a", Attributes = Fragmentattributename)] [Targetelement ("a", Attributes = Hostattributename)] [Targetelement ("a", Attributes = Protocolattributename)] [Targetelement ("a", Attributes = Routeattributename)] [Targetelement ("a", Attributes = Routevaluesdictionaryname)] [Targetelement ("a", Attributes = Routevaluesprefix + "*")]public class anchortaghelper:taghelper{Private Const Strin G Actionattributename = "asp-action"; Private Const string controllerattributename = "Asp-controller"; Private Const string fragmentattributename = "Asp-fragment"; Private Const string hostattributename = "Asp-host"; Private Const string protocolattributename = "Asp-protocol"; Private Const string routeattributename = "Asp-route"; Private Const string routevaluesdictionaryname = "Asp-all-route-data"; Private Const string Routevaluesprefix = "asp-route-"; Private const string href = "href"; ...}
As can be seen above, the taghelper will be applied to a tag, and this tag needs to have asp-action, Asp-controller, Asp-fragment, Asp-host, Asp-protocol, Asp-route, Asp-all-route-data and asp-route-* One or more of these attributes, otherwise the tag is bound to the taghelper. In the last conditional binding, a wildcard character * is used, which is also supported on BETA5.
Like what
<a href= "http://www.cnblogs.com/liontone/" > Good water </a>
Will not be applied on anchortaghelper.
- Remove Activate attribute.
before:
public class mytaghelper:taghelper{ [Htmlattributenotbound] [Activate] public ihtmlencoder Encoder {get ; Set } [Htmlattributenotbound] [Activate] public viewcontext viewcontext {get; set;}}
Right now:
public class mytaghelper:taghelper{public mytaghelper (Ihtmlencoder encoder) { encoder = encoder; } Public Ihtmlencoder Encoder {get;} [Htmlattributenotbound] [ViewContext] Public ViewContext ViewContext {get; set;}}
- attribute is not allowed to be named "data-*".
The attribute name in BETA5 cannot begin with "data-", otherwise there will be an error when parsing the taghelper.
- New Htmlattributenotboundattribute, the properties that can be exposed in a class are not converted to Taghelper attribute.
See here for a detailed introduction.
Like whatpublic class mytaghelper:taghelper{public mytaghelper (Ihtmlencoder encoder) { encoder = encoder; } Public Ihtmlencoder Encoder {get;} [Htmlattributenotbound] [ViewContext] Public ViewContext ViewContext {get; set;}}
According to the previous article, ViewContext corresponds to Taghelper attribute is view-context, but in fact we do not want it to become attribute, Just add htmlattributenotboundattribute and there's no smart tip for that attribute in Visual Studio 2015.
- Embedded resource in the assembly key has been returned to ASP. Namespace + "." + file name
In the BETA4 key is the same as the relative path of the file, which is more unusual, perhaps Microsoft has discovered this problem, to BETA5 and return to the previous, key generation is the namespace + "." + file name.
- Taghelperoutput has added 2 new properties: Preelement and Postelement.
Unlike Precontent and Postcontent, these two properties can be used to output content to the front or back of the current tag, and you can see the corresponding issue on GitHub for more information.
For example, overriding a method in a class:
public void Process (taghelpercontext context, taghelperoutput output) { var nl = environment.newline; var br = "<br/>" + nl; Output. Preelement.append ("This would appear before source element" + br); Output. Precontent.append (nl + "This would appear before source content" + br); Output. Postcontent.append (BR + "This would appear after source content" + nl); Output. Postelement.append (BR + "This would appear after source element");}
On the View Taghelper:
<my-tag-helper> Content in source</my-tag-helper>
The content that is generated to the page after the last parse is:
This would appear before source Element<br/><my-tag-helper>this would appear before source content<br/>< C0/>content in Source<br/>this would appear after source Content</my-tag-helper><br/>this would appear a fter source Element
- Project.json in preprocess default path is Compiler/preprocess/**/*.cs, where the name of the folder is lowercase, if the program is the folder name uppercase, the inside of the code will not be executed.
Originally the corresponding folder in my project is uppercase Compiler/preprocess, in doing BETA4 upgrade to BETA5 support, found that the code is not executed, and then try to directly set preprocess in Project.json to compiler/ Preprocess/**/*.cs, this is possible. But think that since the document says that the default path is the address, why should it be set? In the baffled solution, suddenly found that it is written in lowercase, so try to change the folder into lowercase, sure enough. It's a big hole. If the folder is case sensitive, then the first step is to be strict. I do not know what will happen after the release of the official version, wait and see.
- BETA5 version of the core of the library more and more perfect, the new Hashtable, ArrayList class
Before the BETA4 version of the core library is not the definition of these two classes, the project is just another use, that had to add their own class, now upgrade to Beta5, and then have, and then the original deleted. As the official version approaches, the core library becomes more and more perfect.
- Some library names, class namespace change, such as:
- Namespaces change from Microsoft.Framework.ConfigurationModel to Microsoft.Framework.Configuration
- Microsoft.Framework.ConfigurationModel.Json Library renamed to Microsoft.Framework.Configuration.Json
- Remove namespace Microsoft.AspNet.Http.Core
- Remove the Entityframewor library and use the Entityframework.sqlserver library instead.
- The method parameter types defined in interface Icompilemodule vary: class Beforecompilecontext Instead of interface Ibeforecompilecontext, Class Aftercompilecontext instead of interface Iaftercompilecontext.
There are other changes, there is no one listed here, everyone in the actual upgrade process according to their own project situation to make corresponding changes.
- Discovered some known issues with BETA5, such as:
In the render section, if you use Anchortaghelper, there will be errors at run time, the corresponding issue is here, I have to use the Anchortaghelper, the HTML element instead of it, It is said that it has been fixed in beta6.
Above is I in the project upgrade process encountered problems, in fact, there are many changes, we need everyone according to their own project situation to find, specific beta5 detailed changes see here.
Changes to taghelper caused by ASP. NET 5 Beta5