0
I have a mvc project in Asp.net core and I’m having problems performing a Submit. Well I "Seto" the properties of my Personal Model.
return new PessoaContatoCorreioEletronicoViewModel
{
UsarParaNotaFiscalEmitida = false,
UsarParaOrdemCompra = false,
UsarParaPedidoVenda = false,
UsarParaMarketing = false
};
The problem is that when I make a Submit, the class gets NULL... It’s as if Asp.net recognized that no checkbox was checked and set the class to null. If I check at least one checkbox works... Only I would like all checkboxes to assume a FALSE default value so this problem doesn’t happen. How do I?
If I do not select any of the Checkbox:
If I Select at least one of the checkbox:
<a class="dropdown-item" role="menuitem"><input data-plugin="switchery" type="checkbox" data-size="small" class="ckb-usar-nf-emitida" data-val="true" value="true" checked="@(Model.PessoaContatoCorreioEletronicoViewModel.UsarParaNotaFiscalEmitida)" id="PessoaContatoCorreioEletronicoViewModel_@(indice)_UsarParaNotaFiscalEmitida" name="PessoasContatosViewModel[@indice].PessoaContatoCorreioEletronicoViewModel.UsarParaNotaFiscalEmitida" /> Usar para NF Emitida</a>
<a class="dropdown-item" role="menuitem"><input data-plugin="switchery" type="checkbox" data-size="small" class="ckb-usar-ordem-compra" data-val="true" value="true" checked="@(Model.PessoaContatoCorreioEletronicoViewModel.UsarParaOrdemCompra)" id="PessoaContatoCorreioEletronicoViewModel_@(indice)_UsarParaOrdemCompra" name="PessoasContatosViewModel[@indice].PessoaContatoCorreioEletronicoViewModel.UsarParaOrdemCompra" /> Usar para Ordem de Compra</a>
<a class="dropdown-item" role="menuitem"><input data-plugin="switchery" type="checkbox" data-size="small" class="ckb-usar-pedido-venda" data-val="true" value="true" checked="@(Model.PessoaContatoCorreioEletronicoViewModel.UsarParaPedidoVenda)" id="PessoaContatoCorreioEletronicoViewModel_@(indice)_UsarParaPedidoVenda" name="PessoasContatosViewModel[@indice].PessoaContatoCorreioEletronicoViewModel.UsarParaPedidoVenda" /> Usar para Pedido de Venda</a>
<a class="dropdown-item" role="menuitem"><input data-plugin="switchery" type="checkbox" data-size="small" class="ckb-usar-marketing" data-val="true" value="true" checked="@(Model.PessoaContatoCorreioEletronicoViewModel.UsarParaMarketing)" id="PessoaContatoCorreioEletronicoViewModel_@(indice)_UsarParaMarketing" name="PessoasContatosViewModel[@indice].PessoaContatoCorreioEletronicoViewModel.UsarParaMarketing" /> Usar para Marketing</a>
<div class="dropdown-divider"></div>
What aspnet is used?
– novic
Asp.net Core 2.0
– Master JR
Use the Razor tags that’s best. this happens because it has nothing to instantiate for this class, maybe if you instantiate in the constructor can fix it, try to do this test
– novic