Change Label in view in Asp.Net MVC Project

Asked

Viewed 1,130 times

1

I created a class in the Model called Payment.Cs, where it has the attributes exactly written as the name of the fields in my payment table in the BD. I created a view to register the payment information, 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 I use a <label> </label> does not take legal formatting. How do I do this?

Follows 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")
}

inserir a descrição da imagem aqui

1 answer

4


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

To perform this setup, simply enter in your payment class the note Display, follows an example below:

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; }
}

Follow an example running on . NET Fiddle: https://dotnetfiddle.net/0IqBpJ

  • Junior thanks guy worked out!

Browser other questions tagged

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