c# - HTML.TextBoxFor 禁用不传递值

标签 c# asp.net-mvc-4

我的观点如下:

@Html.TextBoxFor(model => model.PersonnelId, new { disabled = "disabled" })

在我的 Controller 中我有这个:

if (ModelState.IsValid)
{
    PersonnelFacade.SavePerson(person);
    return RedirectToAction("Index");
}

现在,当我检查 person.PersonnelId 时,它是空的。 当我删除 {disabled = "disabled"} 它工作正常但我可以更改 PersonnelId 这不是我想要做的。

我做错了什么?

最佳答案

尝试 2 个值

  1. PersonnelIdForDisplay
  2. 人员编号

然后在你看来

  1. @Html.TextBoxFor(model => model.PersonnelIdForDisplay, new { disabled = "disabled"})
  2. @Html.HiddenFor(p => p.PersonnelId)

关于c# - HTML.TextBoxFor 禁用不传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13267747/

相关文章:

c# - 从代码和网站调用Web API

c# - MVC 模型在发布时为空

c# - 如何在 c# 中单击按钮时显示 iframe,并在显示另一个网格或 iframe 时使其不可见?

c# - 如何解决无法连接到 SQL Server 数据库?

dependency-injection - MVC 4 和 Unity,向 WebAPI Controller 注入(inject)依赖项

c# - 找不到与请求 URI 'Myurl' 匹配的 HTTP 资源 在 Controller 'controllername' 上找不到与请求匹配的操作

asp.net-mvc-4 - 如何在 MVC 4 的请求中获取查询字符串变量?

c# - 如何使 waitForWebPageToLoad 在编码的 ui 测试中工作?

c# - 使用 `StackExchange.Precompilation` ,如何输出构建错误?

c# - "Core"作为成员名后缀的含义