asp.net mvc 中的 Html.TextAreaFor
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Razor 时使用以下代码
Use the code below when using Razor
使用 ASP.NET MVC 的
Html
帮助程序渲染TextArea
和使其可调整大小是两个不同的问题。使用Html
帮助器时,您可以向textarea
添加一个类,例如然后您可以使用 jQuery 挂钩该类,以使其在网页上呈现时可调整大小。请参阅实现可调整大小的文本区域?,了解有关制作
文本区域 可调整大小。
Rendering
TextArea
using ASP.NET MVC'sHtml
helper and making it resizable are two different concerns. When usingHtml
helper you can add a class totextarea
likeThen 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.更好的是,如果您想自动计算文本区域中的行数,您可以使用它
Even better, if you want auto-calculate number of the rows in the textarea you can use this