Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET MVC,添加单个属性_Asp.net_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

ASP.NET MVC,添加单个属性

ASP.NET MVC,添加单个属性,asp.net,asp.net-mvc,asp.net-mvc-3,Asp.net,Asp.net Mvc,Asp.net Mvc 3,对于属性=我使用的值 @Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control", placeholder="Email address" }) 它给了我: <input class="form-control" id="Email" name="Email" placeholder="Email address" type="email" value="" /> 如何向该属性

对于属性=我使用的值

@Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control",
 placeholder="Email address" })
它给了我:

<input class="form-control" id="Email" name="Email" placeholder="Email address"
 type="email" value="" />
如何向该属性添加单个属性,因此我需要必选和自动聚焦:

<input class="form-control" id="Email" name="Email" placeholder="Email address" 
type="email" value=""  required autofocus />
谢谢

如果使用string.Empty,将在生成的html中获得一个空属性

@Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control",
placeholder = "Email address", required = string.Empty, autofocus = string.Empty })
如果使用string.Empty,将在生成的html中获得一个空属性

@Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control",
placeholder = "Email address", required = string.Empty, autofocus = string.Empty })

使用新的{required=required}有什么问题?据我所知,这是唯一的办法。这不会给你想要的标记,但它仍然有效。使用新的{required=required}可能会重复什么错误?据我所知,这是唯一的办法。这不会给你你想要的标记,但它仍然可以工作。它的可能重复生成我:autofocus=和required=,但我只需要autofocusrequired@ihorko那很有趣。。。对我来说,我只得到所需的autofocusautofocus=仍然有效。它生成我:autofocus=和required=,但我只需要自动对焦required@ihorko那很有趣。。。对我来说,我只得到所需的autofocusautofocus=仍然有效。