【问题标题】:creating textarea with htmlhelper in asp .net mvc 4在asp .net mvc 4中使用htmlhelper创建textarea
【发布时间】:2013-01-11 12:17:35
【问题描述】:

使用:ASP .NET MVC 4 在我的一个页面中,我需要一个具有一定宽度和高度的 textarea,使用 html helper class。我的一些代码如下:

    <div class="editor-label">
        @Html.LabelFor(model => model.MailSubject)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.MailSubject)
        @Html.ValidationMessageFor(model => model.MailSubject)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.MailBody)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.MailBody)
        @Html.ValidationMessageFor(model => model.MailBody)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Content)
    </div>
    <div class="editor-field1">
        @Html.EditorFor(model => model.Content)
        @Html.ValidationMessageFor(model => model.Content)
    </div>

我想知道如何定义 editorfor(model.content) 的大小(宽度/隐藏)?

【问题讨论】:

标签: asp.net-mvc-4 textarea html-helper


【解决方案1】:

我知道这个问题已经有一年多了,但以防万一有人在寻找答案,这里是:

Html.TextAreaFor(model => model.Field, new { rows = "", cols = "", style = "width: 90%; height: 50px;" })

您可以应用内联样式或使用类声明。这将在页面上呈现文本区域,如下所示:

<textarea class="swiper-no-swiping" name="model.Field" cols="" rows="" style="width: 90%; height: 50px;"></textarea>

【讨论】:

    【解决方案2】:

    我遇到了这个问题。我是新手,所以我不太确定,但使用以下我能够调整高度...

    @Html.TextAreaFor(model => model.FullItinerary, 20, 10, null)
    

    我仍然不知道如何调整宽度,我目前的谷歌任务......

    【讨论】:

      【解决方案3】:

      编写一个客户助手,或扩展 TextAreaFor 助手的功能。

      这里有一个资源可以帮助您创建自定义助手:http://www.simple-talk.com/dotnet/asp.net/writing-custom-html-helpers-for-asp.net-mvc/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-16
        • 1970-01-01
        • 2014-10-10
        • 2023-03-25
        • 2013-02-27
        • 2014-12-30
        • 1970-01-01
        • 2015-01-14
        相关资源
        最近更新 更多