Change Label in view in Asp.Net MVC Project

0

I created a class in the Model named Payment.cs, where it has the exactly spelled attributes as the name of the fields of my pay table in the DB. I created a view for the payment information to be registered, but besides creating the view and linking to a model to generate the fields automatically, I would like to edit the display of the label because the name of the field that it takes from the model is not legal , and if you use a <label> </label> does not get legal formatting. How do I do that?

Follow the code below:

@model SistemaPagamento.Models.Pagamento

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Pagamento</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.IdPagamento, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.IdPagamento, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.IdPagamento, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.USUARIO_IdUsuario, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.USUARIO_IdUsuario, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.USUARIO_IdUsuario, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.FORNECEDOR_IdFornecedor, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.FORNECEDOR_IdFornecedor, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.FORNECEDOR_IdFornecedor, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DtEmissao, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DtEmissao, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DtEmissao, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DtVencimento, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DtVencimento, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DtVencimento, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.NF, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.NF, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.NF, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Boleto, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Boleto, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Boleto, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Valor, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Valor, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Valor, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Descricao, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Descricao, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Descricao, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DtEntrega, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DtEntrega, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DtEntrega, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

    
asked by anonymous 08.09.2017 / 03:21

1 answer

2

If you want to change the name of your form, you can use DataAnnotations in your entities.

To perform this configuration, simply enter the Display annotation in your payment class, here's an example:

public class Pagamento
{
    [Display(Name = "Código:")]
    public string IdPagamento { get; set; }

    [Display(Name = "Usuário:")]
    public string USUARIO_IdUsuario { get; set; }
    [Display(Name = "Fornecedor:")]
    public string FORNECEDOR_IdFornecedor{ get; set; }

    [Display(Name = "Data Emissao:")]
    public DateTime DtEmissao { get; set; }

    [Display(Name = "Data Vencimento:")]
    public DateTime DtVencimento { get; set; }

    [Display(Name = "Nota Fiscal:")]
    public string NF{ get; set; }

    [Display(Name = "Boleto:")]
    public string Boleto{ get; set; }
}

Here is an example working in .NET Fiddle: link

    
08.09.2017 / 04:17