asp.net razor:post返回的模型不包含更改的数据

wlwcrazw  于 2022-11-19  发布在  .NET
关注(0)|答案(1)|浏览(123)

我有这个页面:

<form action="@Url.Action("SaveIndex")" method="POST" id="idForm">
  @Html.HiddenFor(m => m.Name[0])       
  @Html.HiddenFor(m => m.AutoCloseWindow)
    <div class="divEditColumns">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr valign="top">
                <td>
                    <div class="Column Column100">
                        <div class="divFieldGroup">
                            <div class="GroupHeadline">Übersetzung</div>
                            <div class="GroupContent">
                                <table cellspacing="" cellpadding="0" border="0">
                                    <tr>
                                        <td class="Label">
                                            <label for="">language</label>
                                        </td>
                                        <td class="Field">
                                            <input type="hidden" name="name1" value="@Model.Name[0]" />
                                            <div class="input-control text">
                                                <input type="text" name="name2" value="@Model.Name[0]" />
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
  
                        </div>
                    </div>
                </td>

            </tr>
        </table>
    </div>
</form>

它显示模型中的数据和一个字段,我可以在该字段中更改“名称”值。
现在,当我按下保存时,这个方法被触发,并且返回我的模型:

public ActionResult SaveIndex(GlobalTaggingLocalizationModel model, bool autoclosewindow = false)
{
   
    return RedirectToAction("Index", new { autoclosewindow = autoclosewindow, refreshOpener = true, id = 0 });
}

但是模型包含来自DB的值(放入模型的原始值),我对模型的更改没有传递到这里。
最好的,
J型

xytpbqjk

xytpbqjk1#

如果要更改文本name2,则需要保持name attribute与model属性相同。
尝试:

<input type="text" name="Name" value="@Model.Name[0]" />

实验结果:

相关问题