MVC中设置文本框不可修改(@Html.TextBox)

mvc前台:

@Html.TextBox("id",“name", new {@Readonly = "True" })

id:是文本框的名称,eg:@Html.TextBox("dome1")

name:是显示在文本框中的值,@Html.TextBox("dome1","显示的值")

new{@Readonly = "True"}:是设置当前文本框只读不可修改 

 

@Html.TextBoxFor,并且我把它设为必需的,但是当我只输入空格时,它可以被保存为空。现在为了避免这种情况,我想发送可以输入的特定值(大约30个值)。如果用户输入一个由我定义的值,在这种情况下,for将被保存。请帮我做这个。

<div style="display: flex; flex-direction: row"> <p>code:</p> @Html.TextBoxFor(model => model.Code, new { @class = "form-control", required = "required" }) </div>

  

 

 posted on 2022-06-20 11:25  代码改变世界&1024  阅读(359)  评论(0编辑  收藏  举报