Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 没有html值的Razor属性_Asp.net Mvc_Razor - Fatal编程技术网

Asp.net mvc 没有html值的Razor属性

Asp.net mvc 没有html值的Razor属性,asp.net-mvc,razor,Asp.net Mvc,Razor,我的文本框现在看起来像这样 @Html.TextBox("Something", "", new { type = "text", min = 1, max = 60, data_validation_integer_regex = @ValidationPatterns.Integer, data_validation_int

我的文本框现在看起来像这样

 @Html.TextBox("Something", "", new
       {                           
          type = "text",
          min = 1,
          max = 60,
          data_validation_integer_regex = @ValidationPatterns.Integer,
          data_validation_integer_message = @ValidationPatterns.IntegerMessage,
          data_bind = "value: observables.Something"
        })
它呈现为

   <input data-bind="value: observables.Something" 
          data-validation-integer-message="Some message" 
          data-validation-integer-regex="^[1-9]\d*$" 
          id="Something" 
          max="60" 
          min="1" 
          name="Something" 
          type="text" 
          value="">

我们正在使用的验证库

我想让我的一些字段成为必填字段,使用这个库的方法是,我需要像这样向输入字段添加一个标记

Razor不允许我这样做,因为它似乎希望所有参数都是这种格式

property=“something”
property=100


如果我想使我的字段成为必填字段,那么我唯一的选择是恢复到标准html标记吗?

如果您使用的属性带有空字符串(
required=”“
),Razor将把它呈现为无值属性。就是

@Html.TextBox("name", "value", new { attr="something", required="" })
呈现为:

<input type='text' name='name' id='id' value='value' attr='something' required />


。。。我没想过要试试为什么/对于MVC5,这不起作用。匿名对象中的
required=“”
required=(string)null
都将呈现
required=“”