HTML Helpers vs. Markup Helper

-1

HTML and tagging helpers seem to be able to perform the same functions, like this example I found in Microsoft documentation :

HTML Help

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizo" }))
{
    @Html.AntiForgeryToken()
    <h4>Create new account.</h4>
    <hr />
    @Html.ValidationSummary("", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBorFor(m => m.Email, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" class="btn btn-default" value="Register" />
        </div>
    </div>
}

Marking aids

<form asp-controller="Account" asp-action="Register" method="post" class="form-horizo">
    <h4>Create new account.</h4>
    <hr />
    <div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
    <div class="form-group">
        <label asp-for="Email" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="Email" class="form-control" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="Password" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="Password" class="form-control" />
            <span asp-validation-for="Password" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="ConfirmPassword" class="form-control" />
            <span asp-validation-for="ConfirmPassword" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" class="btn btn-default" value="Register" />
        </div>
    </div>
</form>

It really seems to me that they do the same things, only with different syntaxes, so the following doubts came to me:

  • Is there any difference in what an HTML helper and a tagging helper can do that the other one does not?
  • Is there a recommendation or good practice on which one to use?
  • In performance, do any of them stand out, or are they equivalent?
asked by anonymous 23.01.2018 / 23:40

1 answer

1
  

Is there any difference in what one HTML helper and one marking helper can do that the other does not?

No. Both were made to work independently.

  

Is there a recommendation or good practice on which one to use?

No. But keep a pattern, your code mates will appreciate it. Anyway, the second way is the new one and the possible HTML Helpers issues have been fixed.

In addition the new form is more like HTML, which makes the code much more standardized

  

In performance, do any of them stand out, or are they equivalent?

None stands out. Neither would have like, since the purpose of the two is to generate HTML. What can happen is to change the compile time, but there is another case and the difference should be very small.

    
24.01.2018 / 12:20