I have a grid and clicking on it I want to open a modal to display the data according to the item that was clicked on the grid. But my modal opens and closes alone and neither is passed the values to it. is as follows.
Code in View:
<div id="modalCadastroCategoria" class="modal" style="display: @(Model.ModalCategoria ? "block" : "none")" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
@{
if (!Model.Consultar)
{
<button type="button" class="close close-modal" data-dismiss="modal">×</button>
}
}
<h4 class="modal-title">Cadastro de Categorias de Materiais Apreendidos:</h4>
</div>
<div class="modal-body" @(Model.Consultar ? "style=overflow-y:auto;height:600px;" : "")>
@Html.Partial("_CadastroCategoriaDeMateriaisApreendido", Model)
</div>
<div class="modal-footer">
<button id="CancelarCadastroCategoria" name="command:CancelarCadastroCategoria" type="submit" class="btn btn-default close-modal">Cancelar</button>
@{
if (!Model.Consultar)
{
<button id="cadastroCategoria" name="command:IncluiCategoria" type="submit" class="close-modal btn btn-success">Incluir</button>
}
}
</div>
</div>
</div>
</div>
Partial Code:
@model SISTEMA.MELHORDESTINO.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" value="Adicionar" class="btn btn-default" name="command:IncluirEspecificacoes:1">
<button id="AdicionaMultiplasEspecificacoes"
name="command:AbrirMultiplasEspecificacoes"
type="submit" class="btn btn-default">
Adicionar Múltiplos
</button>
</div>
</div>
}
}
Controller code:
private async void EditarCategoriaAlterar(IncluirMaterialViewModel model)
{
var newModel = model;
ModelState.Clear();
await this.BuscarMaterial(model.CodigoMaterial, "Alterar");
model = newModel;
}