当我将禁用属性放入 html 输入标记 asp.net-core mvc 时不映射它

mil*_*c88 1 asp.net-core-mvc asp.net-core

设想:

现在这对我来说很奇怪。当我将表单提交到控制器时,所有输入字段都被正确映射,但是:

<input asp-for="Id" disabled class="form-control" value="something"/>
Run Code Online (Sandbox Code Playgroud)

不会(始终为空)。

问题是:

当我删除禁用时效果完美!

我有另一个页面具有类似的禁用输入字段,并且该页面工作正常。这里发生了什么?

Xue*_*hen 6

HTML中元素的disabled属性用于指定输入字段被禁用。禁用的输入无法点击且无法使用。它是一个布尔属性。禁用的元素不会在表单中提交。

您可以使用只读而不是禁用

<input asp-for="Id" readonly class="form-control" value="[something]" />
Run Code Online (Sandbox Code Playgroud)

参考:https ://stackoverflow.com/a/1355734/10201850