HTML vs markup auxiliaries

Asked

Viewed 72 times

-1

Apparently HTML and markup helpers can perform the same functions, like this example I found in microsoft documentation:

HTML auxiliaries

@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 I came up with the following doubts:

  • There is some difference in what one HTML helper and one markup helper can do that the other cannot?
  • Is there any recommendation, or good practice on which one I should use?
  • In terms of performance, some of them stand out, or are equivalent?
  • 1

    Always put code as text formatting with Ctrl+K or by clicking the button {} of the editor.

  • @Isac Actually the intention was just to add a small part of the example in the Microsoft documentation (which uses these images), I will write the code then.

  • Can you please tell me the reason for the negatives, so I can edit the question to fit? : D

1 answer

1


There is some difference in what one HTML helper and one markup helper can do that the other cannot?

No. The two were meant to work independently.

Is there any recommendation, or good practice on which one I should use?

No. But keep a pattern, your codemates will appreciate it. Anyway, the second way is the new one and the possible problems of the HTML Helpers have been solved.

In addition the new shape is more similar to HTML, which makes the code much more standardized

In terms of performance, some of them stand out, or are equivalent?

Neither one stands out. Neither would it be possible, since the goal of the two is to generate HTML. What can happen is to change the time of "compilation", but there is another case and the difference must be tiny.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.