Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Asp net mvc表单不会像预期的那样在提交时发布所有字段_Javascript_Jquery_Html_Forms - Fatal编程技术网

Javascript Asp net mvc表单不会像预期的那样在提交时发布所有字段

Javascript Asp net mvc表单不会像预期的那样在提交时发布所有字段,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我的asp net mvc应用程序中有此表单,请在表单上方选中已发布的字段。这对夫妇失踪了。不明白为什么 <form id="FormRegistroUsuario" action="/Account/AdminSecurityUserAccountAdd"> <fieldset> <legend><h2 style="color:black;">Cadastro novo Usuário</h2></leg

我的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>
已发布的字段:

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'" : "" />
}

@for(int counter=0;counter在数组中循环时,需要在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'" : "" />
}

用于(int counter=0;counter发现问题。隐藏字段位于获取
display:none
的div内,因此未发布值。只是移动到我的表单顶部,它现在正在工作。

发现问题。隐藏字段位于获取
display:none
的div内,因此未发布值。只是移动到在我的窗体顶部,它现在正在工作。

我遇到了类似的问题。我只使用了ID属性,没有使用名称。 添加name属性后,该字段已提交

之前:

<input type="text" id="txt" class="form-control" />

修正:


我遇到了类似的问题。我只使用了ID属性,没有使用名称。 添加name属性后,该字段已提交

之前:

<input type="text" id="txt" class="form-control" />

修正:



你的隐藏字段没有任何价值,也许这就是它们没有被包括在内的原因。哈哈…伙计,我没有想过。我来自巴西。谢谢你。我现在就改变!这就是为什么人们必须使用抽象作为工具,但要了解其内部工作。你的隐藏字段没有价值,也许这就是它们没有被包括在内的原因。哈哈…伙计,我我没有想过。我来自巴西。谢谢你。我现在就改变!这就是为什么必须使用抽象作为工具,但要了解内部工作。这是在asp net mvc中使用复选框的html帮助程序时的标准行为。值始终设置在元素的索引0中,该元素始终包含元素[0]和元素[1]这是在asp net mvc中使用复选框的html帮助程序时的标准行为。值始终在始终包含元素[0]和元素[1]的元素的索引0中设置