回发时输入文本,恢复为 NULL

本文关键字:恢复 NULL 文本 输入 | 更新日期: 2023-09-27 18:36:34

有人可以告诉我为什么复选框"userId"的 id 在开机自检时返回空

<input type='checkbox' onclick='$("#userId").val("@user.Id"); return true; '/>
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "ChangeUserAccount"), FormMethod.Post))
 {
   <input type="text" id="userId" />
   <input type="submit" id="btn" name="btnSubmit" value="Update" style="float:right;"  />
 }
[HttpPost, ActionName("Index")]
 [Authorize]
 public ActionResult IndexPOST(UserLoginRecordIndexVM model, int? userId)
    {

因此,在屏幕上,文本框包含复选框的正确ID,但是当我单击"更新"按钮时,返回NULL ??

回发时输入文本,恢复为 NULL

你为什么不利用这个帮助程序:

 @Html.TextBox("userId", null, new { id = "userId" });

这会将相应的idname属性添加到文本框中。

只需添加 name 属性:

<input type="text" id="userId" name="userId" />

但是,还要确保操作接受它作为参数、string userId或者它是回发的模型的一部分。因此,在您的情况下,您可以这样做:

public ActionResult IndexPOST(UserLoginRecordIndexVM model, string userId)