如何在视图MVC中更改textboxfor的大小

时间:2018-01-16 21:32:35

标签: c# html asp.net-mvc

我正在尝试使用新的htmlAttributes更改TextBoxFor的大小,但它没有使用任何其他解决方案?

    <td>
        @Html.TextBoxFor(model => model.Serial_No, htmlAttributes: new { @style= "size:10" })

    </td>

3 个答案:

答案 0 :(得分:0)

您需要确定要使用哪些css属性来指定文本框的大小。考虑身高:&#34; xxxpx&#34;,font-size:&#34; yyypx&#34;开头。

通常,使用Chrome调试器(F12)检查生成的元素并确定html将解决您的问题是很有帮助的。然后,您可以将其转换回正确的样式htmlAttribute。

答案 1 :(得分:0)

@Html.EditorFor(model => model.Serial_No, new { htmlAttributes = new { @class = "yourCustomClass" } })

然后在css文件中

yourCustomClass{
height: 60px;
min-width:400px;
etc;
}

如果按大小表示最大字符数,则

@Html.TextBoxFor(m=> m.Serial_No,  new { maxlength="10" });

答案 2 :(得分:-1)

@ Html.TextBoxFor(model =&gt; model.Serial_No,new {style =“width:10px”})