TextAreaFor无法设置宽度 [英] TextAreaFor Cannot Set Width

查看:91
本文介绍了TextAreaFor无法设置宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在textarea中设置宽度或列数.行/高度效果很好.有人可以帮忙谢谢!

I cannot set the width or cols in atextarea. Rows/Height works just fine. can someone please help thanks!

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    @Html.ValidationSummary(true)
    @Html.TextAreaFor(model => model.Comments, new {cols=60, rows=10})
    @Html.HiddenFor(model => model.UserName, new { UserName = @User.Identity })

    <div class="form-group">
        <div class="col-md-10">
            <input type="submit" value="Submit Feedback" class="btn btn-default" />
        </div>
    </div>
}

任何建议或技巧将不胜枚举!谢谢

Any advice or tips would be greatly appricated! thanks

呈现的HTML是(出于安全原因,我删除了名称和值文本:

The HTML rendered is (I removed name and value text for security reasons:

<form action="/feedback/create" method="post"><input name="" type="hidden" value="">        
<textarea name="Comments" id="Comments" rows="10" cols="60"></textarea>
<input name="UserName" id="UserName" type="hidden" value="" username="System.Security.Principal.WindowsIdentity">        

<div class="form-group">
        <div class="col-md-10">
            <input class="btn btn-default" type="submit" value="Submit Feedback">
        </div>
 </div>

我可以通过CSS设置文本区域的宽度,但只能扩展到一定程度(可能是屏幕的15%)

I can set the width of the textarea via CSS but only to a certain exten ( maybe 15% of the screen)

推荐答案

所以我弄清楚了,我相信这是导入到ASP.NET MVC5项目中的引导程序的问题.答案很简单.也只需设置CSS

so I figured it out, I believe this is a problem with bootstrap imported to a ASP.NET MVC5 project. The answer is easy though. Just set CSS too

    max-width: 1000px;
    width: 1000px;

这可以解决所有数据类型的问题.文本区域,输入法等

That fixes it for all datatypes. Textarea, input, etc.

**** 更新8/26/2014 ****

**** UPDATE 8/26/2014 ****

更改了我的答案以反映发布的评论.使用百分比而不是px来保持响应速度. CSS应该是:

Changed my answer to reflect on a comment posted. Use percentages rather then px to keep responsiveness. The CSS should be:

    max-width: 100%;
    width: 100%;

**** 更新8/29/2016 ****

**** UPDATE 8/29/2016 ****

此问题已在Bootstrap 3中修复.添加适用于上述样式的类 form-control

This was fixed with Bootstrap 3. Add the class form-control which applies the above styling

     @Html.TextAreaFor(x => x.Note, new { @class = "form-control", rows = "3" })

这篇关于TextAreaFor无法设置宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆