I have this form in my asp net mvc application, check right above the form the fields that are posted. The are couple of them missing. Can´t understand why
<form id="FormRegistroUsuario" action="/Account/AdminSecurityUserAccountAdd">
<fieldset>
<legend><h2 style="color:black;">Cadastro novo Usuário</h2></legend>
<table id="tblUsuario">
<tr>
<td class="smallField">Username:</td>
<td>@Html.TextBoxFor(m => m.UserName,new { @class = "validate[required]" }) </td>
<td class="smallField" style="padding-left:10px;">Email:</td>
<td>@Html.TextBoxFor(m => m.Email, new { @class = "validate[required,custom[email]]" }) </td>
<td style="padding-left:10px;">Ativo:</td>
<td>@Html.CheckBoxFor(m => m.Active)</td>
</tr>
<tr>
<td class="smallField">Senha:</td>
<td>@Html.PasswordFor(m => m.Password, new { @class = "validate[required, minSize[7]]" }) </td>
<td style="padding-left:10px;">Repetir Senha:</td>
<td>@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "validate[required,equals[Password]]" }) </td>
<td style="font-size:10px; padding-left:10px;">Habilitar Login com Cert. Digital:</td>
<td>@Html.CheckBoxFor(m => m.isCertifiedAdd)
<div id="certDigitalBlockAdd">
<table>
<tr>
<td class="smallField">Tipo do Certificado:</td>
<td>@Html.DropDownListFor(m => m.certTypeAdd, new SelectList(Model.certTypeComboBox, "id", "type"), "Escolha...", new { @class="smallField" })</td>
<td style="display:none;">@Html.Hidden("certTypeAddHidden")</td>
</tr>
<tr>
<td>Identificação:</td>
<td>@Html.TextBoxFor(m => m.identifierAdd, new { @class = "validate[required] smallField" })</td>
<td style="display:none;">@Html.Hidden("identifierAddHidden")</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td class="smallField">Pergunta Secreta:</td>
<td>@Html.TextBoxFor(m => m.SecretQuestion, new { @class = "validate[required]" }) </td>
<td style="padding-left:10px;">Resposta:</td>
<td>@Html.TextBoxFor(m => m.SecretQuestionPassword, new { @class = "validate[required, minSize[6]]" }) </td>
<td></td>
<td></td>
</tr>
</table>
<br />
<div class="scrollTable" style="margin-left:20px;">
<span class="boxTitle"><table><tr><td>Grupos Disponíveis</td></tr></table></span>
<!-- Tipos -->
<div class="scroller">
<table>
<!-- Indices Disponíveis (Exibidos) -->
@{
counter = 1;
}
@foreach (var role in Model.roles)
{
<tr id="@counter" class="whiteRow setIndex">
<td class="adminTipoFormRowIndex">@role</td>
</tr>
counter++;
}
</table>
</div>
</div>
<div class="scrollTable" style="margin-left:60px;">
<span class="boxTitle"><table><tr><td>Grupos Atribuidos</td></tr></table></span>
<!-- Tipos -->
<div class="scroller scrollerindex">
<table>
@{
counter = 1;
}
@foreach (var role in Model.roles)
{
string count = counter + "_a";
string inputCount = counter + "_i";
<tr id="@count" class="whiteRow unsetIndex" style="display:none;">
<td class="adminTipoFormRowIndex">@role</td>
<input type="hidden" id="@inputCo**strong text**unt" name="rolesGroup" value="@role" disabled="disabled"/>
</tr>
counter++;
}
</table>
</div>
</div>
<input type="submit" value="Salvar" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only button-link submitAddTipo"/>
</fieldset>
</form>
JS:
$('#FormRegistroUsuario').submit(function (e) {
e.preventDefault();
var form = $(this);
console.log(form.serialize());
});
Fields been posted:
UserName=Guilherme
Email=grlongo.ireland%40gmail.com
Active=true
Active=false
Password=%23t1g2p3&
ConfirmPassword=%23t1g2p3&
isCertifiedAdd=true
isCertifiedAdd=false
SecretQuestion=Qual+a+senha%3F&
SecretQuestionPassword=secreta
rolesGroup=Administrador
Does not matter if I use @Ajax.beginForm or this approach the result is the same.
- Sent using Ajax.beginForm
- and ajax submit handle
- Created hidden extras hidden fields to check if they would be posted
(And no).
Any help you be very appreciated.
Found the problem. Hidden fields were inside the div that gets
display:noneso the values were not posted. Just moved to the top of my form and it is working now.