asp.net mvc 中的 Html.TextAreaFor

发布于 2024-11-05 04:46:00 字数 2392 浏览 0 评论 0原文

我有一个 asp.net mvc 视图,允许用户在文本区域中输入一些描述。

我面临两个问题。

当我展开文本区域时,它会在不移动其他 html 元素的情况下展开,或者我无法创建 Html.TextBoxFor () 多行文本框。谁能提出解决方案?如果使用 Textarea 如何使其扩展(大小增长)以便它不与其他元素重叠或如何使用 Html.TextBoxFor() 进行多行?

这就是我的代码的样子

<% using (Html.BeginForm())
        { %>
     <%: Html.ValidationSummary(true)%>

    <fieldset>

        <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageID)%>
        </div>
        <div class ="editor-field1">
             <%: Html.HiddenFor(Model => Model.PackageID)%>
              <%: Html.DisplayFor(Model => Model.PackageID)%>
             <%: Html.ValidationMessageFor(Model => Model.PackageID)%>
        </div>

         <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageName)%>
        </div>
        <div class ="editor-field1">
            <%: Html.TextBoxFor(Model => Model.PackageName)%>
            <%: Html.ValidationMessageFor(Model => Model.PackageName)%>
        </div>

        <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageDesc)%>
        </div>
        <div class ="editor-field1" style= "padding-bottom: 50px; margin-bottom: 150px">
            <%: Html.TextBoxFor(Model => Model.PackageDesc, new { TextMode = TextBoxMode.MultiLine, cols = "55", rows = "10" })%>

            <%: Html.ValidationMessageFor(Model => Model.PackageDesc)%>
        </div>

         <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageTitle)%>
        </div>
        <div class ="editor-field1">
            <%: Html.TextBoxFor(Model => Model.PackageTitle)%>
            <%: Html.ValidationMessageFor(Model => Model.PackageTitle)%>
        </div>
        <div class ="editor-label">
            <%: Html.Label("Project ID") %>
        </div>
        <div class="editor-field">
            <%:Html.DropDownList("ProjectID", (IEnumerable<SelectListItem>)ViewData["projects"])%>
        </div>
         <div>
                <input type="submit" value="Save Edit" />
         </div>
    </fieldset>
    <% } %>

I have a asp.net mvc view that allows the user to enter some description in a textarea.

There are two problems that I am facing.

Either when I expand the textarea it is expanding without moving other html elements or I am not able to make create a Html.TextBoxFor () multiline textbox. Can anyone suggest a solution to this? If Use Textarea how to make it expand(grow in size) so that it does not overlap with other elements or how to use Html.TextBoxFor() for multiline?

This is how my code looks like

<% using (Html.BeginForm())
        { %>
     <%: Html.ValidationSummary(true)%>

    <fieldset>

        <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageID)%>
        </div>
        <div class ="editor-field1">
             <%: Html.HiddenFor(Model => Model.PackageID)%>
              <%: Html.DisplayFor(Model => Model.PackageID)%>
             <%: Html.ValidationMessageFor(Model => Model.PackageID)%>
        </div>

         <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageName)%>
        </div>
        <div class ="editor-field1">
            <%: Html.TextBoxFor(Model => Model.PackageName)%>
            <%: Html.ValidationMessageFor(Model => Model.PackageName)%>
        </div>

        <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageDesc)%>
        </div>
        <div class ="editor-field1" style= "padding-bottom: 50px; margin-bottom: 150px">
            <%: Html.TextBoxFor(Model => Model.PackageDesc, new { TextMode = TextBoxMode.MultiLine, cols = "55", rows = "10" })%>

            <%: Html.ValidationMessageFor(Model => Model.PackageDesc)%>
        </div>

         <div class="editor-label1">
            <%: Html.LabelFor(Model => Model.PackageTitle)%>
        </div>
        <div class ="editor-field1">
            <%: Html.TextBoxFor(Model => Model.PackageTitle)%>
            <%: Html.ValidationMessageFor(Model => Model.PackageTitle)%>
        </div>
        <div class ="editor-label">
            <%: Html.Label("Project ID") %>
        </div>
        <div class="editor-field">
            <%:Html.DropDownList("ProjectID", (IEnumerable<SelectListItem>)ViewData["projects"])%>
        </div>
         <div>
                <input type="submit" value="Save Edit" />
         </div>
    </fieldset>
    <% } %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何以心动 2024-11-12 04:46:00

使用 Razor 时使用以下代码

   @Html.TextAreaFor(model => model.Comments, 10, 40, null);

Use the code below when using Razor

   @Html.TextAreaFor(model => model.Comments, 10, 40, null);
落花浅忆 2024-11-12 04:46:00

使用 ASP.NET MVC 的 Html 帮助程序渲染 TextArea 和使其可调整大小是两个不同的问题。使用 Html 帮助器时,您可以向 textarea 添加一个类,例如

<%:Html.TextAreaFor(x => x.SomeProperty, new { @class = "resizer" }) %>

然后您可以使用 jQuery 挂钩该类,以使其在网页上呈现时可调整大小。请参阅实现可调整大小的文本区域?,了解有关制作文本区域 可调整大小。

Rendering TextArea using ASP.NET MVC's Html helper and making it resizable are two different concerns. When using Html helper you can add a class to textarea like

<%:Html.TextAreaFor(x => x.SomeProperty, new { @class = "resizer" }) %>

Then you can hook this class with jQuery to make it resizable when it's rendered on the web page. Please refer to Implementing a resizable textarea? for information about making your textarea resizable.

栖竹 2024-11-12 04:46:00

更好的是,如果您想自动计算文本区域中的行数,您可以使用它

@Html.TextAreaFor(m => m.Comments, Model.Comments.Count + 1, 40, null)

Even better, if you want auto-calculate number of the rows in the textarea you can use this

@Html.TextAreaFor(m => m.Comments, Model.Comments.Count + 1, 40, null)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文