gpt4 book ai didi

javascript - Asp net mvc Form 不会像应该发布的那样在提交时发布所有字段

转载 作者:行者123 更新时间:2023-11-30 10:34:50 26 4
gpt4 key购买 nike

我的 asp net mvc 应用程序中有此表单,请检查表单正上方发布的字段。他们中有几个人失踪了。不明白为什么

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

已发布的字段:

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

不管我使用@Ajax.beginForm 还是这种方法,结果都是一样的。

  • 使用 Ajax.beginForm 发送
  • 和 ajax 提交句柄
  • 创建隐藏的额外隐藏字段以检查它们是否会发布(没有)。

非常感谢您的任何帮助。

最佳答案

当您在数组中循环时,您需要在 HTML 中使用相同的技术...

例如,在您的Model.roles 集合中,您需要这样做:

@for (int counter = 0; counter <= Model.roles.Count(); counter++)
{
var role = Model.roles[counter];

<input type="checkbox"
id="roles_@counter"
name="roles[@counter]"
value="@role" @(role.active ?? "checked='checked'" : "" />
}

为了简化而删除了代码

并且记住永远不会发布任何空白字段...

顺便说一句:您的表单中确实只有一个 Active 属性,但是通过提交它会写入两个...您生成的 HTML 是什么?

关于javascript - Asp net mvc Form 不会像应该发布的那样在提交时发布所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com