Text field does not take value asp.net MVC

0

I have a text field in my system called NomeEspecificacao , but when I fill in any value in it, it is always returned null in my Action, that is, the word that I write in the text field never comes.

View Code:

model SEMA.Fiscalizacao.Presentation.Web.Models.IncluirMaterialViewModel
@{
    var disabled = Model.Consultar ? "disabled=\"disabled\"" : "";
}

@{
    if (Model.Consultar)
    {
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    @Html.LabelFor(model => model.NomeMaterialCategoria, "Categoria")
                    @Html.EditorFor(model => model.NomeMaterialCategoria, new { htmlAttributes = new { @class = "form-control", @maxlength = 50, disabled } })
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    @Html.LabelFor(model => model.NomeMaterialCategoria, "Categoria")
                    @Html.EditorFor(model => model.NomeMaterialCategoria, new { htmlAttributes = new { @class = "form-control", @maxlength = 50 } })
                </div>
            </div>
        </div>
    }
}


@Html.Partial("_SelectMutipleUnidadesMedida", Model)

<hr class="hr-text" data-content="Especificação da Categoria" />

@{
    if (Model.Consultar)
    {
        <div class="row">
            <div class="col-md-12">
                @{
                    if (!string.IsNullOrWhiteSpace(Model.NomeMaterial) && Model.NomeMaterial.Length > 0)
                    {
                        @Html.TextBoxFor(model => model.NomeEspecificacao, new { @class = "form-control margin-bottom", @maxlength = 50 })
                    }
                    else
                    {
                        @Html.TextBoxFor(model => model.NomeEspecificacao, new { @class = "form-control margin-bottom", @maxlength = 50, disabled })
                    }
                }


            </div>
        </div>
    }
    else
    {
        <div class="row">
            <div class="col-md-12">
                @Html.TextBoxFor(model => model.NomeEspecificacao, new { @class = "form-control margin-bottom", @maxlength = 50 })
            </div>
        </div>

        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-right margin-bottom">
                <input type="submit" id="AdicionarEspecificacao" value="Adicionar" class="btn btn-default" name="command:IncluirEspecificacoes:1">
                <button type="submit" id="AdicionaMultiplasEspecificacoes" class="btn btn-default" name="command:AbrirMultiplasEspecificacoes">
                    Adicionar Múltiplos
                </button>
            </div>
        </div>
    }
}


@if (Model.ListaMaterialCategoriaEspecificacoes != null && Model.ListaMaterialCategoriaEspecificacoes.Count > 0)
{
    <div class="row">
        <div class="col-md-12">
            @Html.Partial("_ListaEspecificacaoCategoria", Model)
        </div>
    </div>
}

Action that returns null in the model:

[HttpPost]
        [CommandName("Alterar", "command:IncluirEspecificacoes:{index}")]
        public async Task<ActionResult> IncluirEspecificacoesAlterarAsync(IncluirMaterialViewModel model)
        {
            var tipoEspc = Convert.ToInt32(RouteData.Values["index"]);


            if (tipoEspc == 1)
            {

                    AdicionaEspecificacao(model, model.NomeEspecificacao);
            }

            if (tipoEspc == 2)
            {
                if (string.IsNullOrWhiteSpace(model.NomeEspecificacaoMultiplo))
                {
                    model.ModalEspecificacoes = true;
                    ErrorMessage = Mensagens.UC027_MSG007;

                    model.CodigoUnidadeMedidaPermitidaUsoSimpViewModel
               .AddRange(model.ListaUnidadeMedidasPermitidasParaUso.Select(x => x.CodigoUnidadeMedida));

                    await PreencherUnidadesMedidaViewModelIncluir(model);
                    await AdicionaUnidadeMedidaPermitidasParaUso(model);

                    return PartialView("_Incluir", model);
                }
                else
                {
                    AdicionaEspecificacao(model, model.NomeEspecificacaoMultiplo);
                }
            }


            model.CodigoUnidadeMedidaPermitidaUsoSimpViewModel
                .AddRange(model.ListaUnidadeMedidasPermitidasParaUso.Select(x => x.CodigoUnidadeMedida));

            await PreencherUnidadesMedidaViewModelIncluir(model);
            await AdicionaUnidadeMedidaPermitidasParaUso(model);
            return PartialView("_Incluir", model);
        }

ResultcomingontheModeljustafterclicking"Add"

Can anyone help me?

Ps: Added images for a better analysis of the problem.

    
asked by anonymous 13.11.2018 / 15:57

1 answer

1

Do not disable the control, put it as readonly and apply CSS styles to appear disabled.

Disabled fields are not posted. This is why DefaultModelBinder can not populate the corresponding property of your model.

    
13.11.2018 / 16:20