Migrating legacy systems to. Net Core 2.0 Diaries (7) Tag Helpers

Source: Internet
Author: User

Tag Helpers is a replacement for HTML helpers

For example, the original view model definition is this:

@using (Html.BeginForm ("Register"," Account", FormMethod.Post,New{@class ="Form-horizontal", role ="form"}) {@Html. AntiForgeryToken ()NewAccount.@Html. ValidationSummary (true,"",New{@class ="Text-danger" })    <divclass="Form-group">@Html. labelfor (M= M.username,New{@class ="col-md-2 Control-label" })        <divclass="col-md-10">@Html. textboxfor (M= M.username,New{@class ="Form-control" })        </div> </div>

In the new version of MVC, we can use tag helper to define:

<form asp-controller=" Account"asp-action="Register"Method="Post" class="Form-horizontal"role="form"> Newaccount."validationsummary.modelonly" class="Text-danger"></div> <divclass="Form-group"> <label asp- for="UserName" class="col-md-2 Control-label"></label> <divclass="col-md-10"> <input asp- for="UserName" class="Form-control"/> <span asp-validation- for="UserName" class="Text-danger"></span> </div> </div>

This is handy for front-end developers, but I have no sense because I am full Stack Develop

If you want to use it, you can refer to this article: http://www.cnblogs.com/TomXu/p/4496480.html

Now there is no outputcache attribute, instead of Microsoft.AspNetCore.ResponseCaching.

[Responsecache (VaryByHeader ="accept-encoding")]  Public Iactionresult About () {}

If you want to use Varybyquerykeys, to first refer to the cache middleware, otherwise it will error InvalidOperationException: ' Varybyquerykeys ' requires the response cache Middleware.

Modify Startup.cs , add the following code to the Configureservices and configure two methods:

 Public class startup{...       Public void configureservices (iservicecollection services)    {        services. Addresponsecaching ();                ...    }       Public void Configure (Iapplicationbuilder app, Iloggerfactory loggerfactory)    {        app. Useresponsecaching ();                ...    }}

Migrating legacy systems to. Net Core 2.0 Diaries (7) Tag Helpers

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.