c# - 如何在 MVC 中指定 textarea 的行列?

标签 c# asp.net-mvc-3 razor

在我的模型中,我有这段代码:

[Required(ErrorMessage = "News content is required.")]

[DisplayName("News Content")]
[DataType(DataType.MultilineText)]
public string FullContent { get; set; }

[Required(ErrorMessage = "News summary is required.")]
[DisplayName("News Summary")]
[DataType(DataType.MultilineText)]
public string Summary { get; set; }  

View 里面是:

<tr>
<td id="td-caption">Full Content</td>  
<td id="td-content2">@Html.EditorFor(model => model.FullContent)  @Html.ValidationMessageFor(model => model.FullContent)</td>  
</tr>  
<tr>
<td id="td-caption">Summary</td>
<td id="td-content2">@Html.EditorFor(model => model.Summary)@Html.ValidationMessageFor(model => model.Summary)</td>
</tr>  

在我的 CSS 中:

textarea#FullContent, #Summary
{
width: 95%;
padding-top: 20px;
padding-left: 20px;
cols: 20;
rows: 20;
}  

但一点作用都没有。我应该怎么办?谢谢!

最佳答案

rowscols 不是有效的 CSS 规则。它们是 textarea 元素的属性。但是由于您使用的是 en EditorFor 帮助程序,因此您无法设置它们的值。您可以在 CSS 中使用 widthheight 属性来调整文本区域的大小:

textarea#FullContent, #Summary {
    width: 90px;
    height: 200px;
    padding-top: 20px;
    padding-left: 20px;
}

关于c# - 如何在 MVC 中指定 textarea 的行列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8666034/

相关文章:

c# - 领域模型上的切换逻辑

c# - 单击同级元素时会触发 Click 事件

c# - Blazor:每次 for 循环旋转时组件不会更新

c# - MVC Razor 字符问题

c# - 在 Azure 表中存储十进制数据类型

c# - 如果查询字符串为空,则返回表中的所有值

c# - 有没有比使用 Console.Clear() 更好的制作控制台游戏的方法?

asp-classic - IIS Express 是否支持调试经典 ASP?

asp.net-mvc-3 - 带有集合的提交对象缺少新集合数据

c# - DBTransaction 回滚抛出