MVC中Html.EditorFor宽度及高度如何设定?

jinseyd 2010-08-10 03:45:00
Html.EditorFor中如何设定高度及宽度,<%: Html.EditorFor(model => model.Content)%>
如何生成像这样的格式:<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>

<%: Html.EditorFor(model => model.Content, new { @style="width:200px;height:150px"}})%>我这样设定不起作用,只用Html.TextBoxFor有效。
...全文
4088 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
http3w 2012-07-15
  • 打赏
  • 举报
回复
<%:Html.TextAreaFor(model => model.Content, 10, 50, new { })%>
10行,50列
guren_d 2012-07-08
  • 打赏
  • 举报
回复
可以更改模型指定绑定的属性
[Required(ErrorMessage = “An Album Title is required”)]
[StringLength(160)]
[DataType(DataType.MultilineText)]
public string Title { get; set; }
这样Html.EditFro(p=>p.Title)
就会生成
<textarea class=”text-box multi-line” id=”Title” name=”Title”>
Let There Be Rock
</textarea>
luxt888 2011-07-09
  • 打赏
  • 举报
回复
.text-box
{
width: 99%;
}

.text-box.multi-line
{
height: 100%;
}
luxt888 2011-07-09
  • 打赏
  • 举报
回复
.text-box
{
width: 99%;
}

.text-box.multi-line
{
height: 100%;
}
随智阔 2011-05-23
  • 打赏
  • 举报
回复
[Display(Name = "描述")]
[StringLength(256)]
[DataType(DataType.MultilineText)]
public string Description { get; set; }





如果该属性是用 MultilineText 特性标记的,该方法就会生成多行文本框的标记。

lxhandlxh01 2011-04-09
  • 打赏
  • 举报
回复
@Html.TextBoxFor(s => s.Title, new { style = "width:30%" })可以调解宽度 但是TextBoxFor最小宽度是80px
jinseyd 2010-08-13
  • 打赏
  • 举报
回复
就是说Html.EditorFor不会生成可调整的高度及宽度的样式,必须改其他方式。
End 2010-08-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hrabeyond 的回复:]
<%= Html.EditorFor(model => model.Content, new { width="200px",height="150px"})%>
[/Quote]
这样也不可以?期待高手。。。。
jinseyd 2010-08-12
  • 打赏
  • 举报
回复
TO:dingji33
用Html.TextAreaFo是可以,Html.EditorFor既然是生成textarea,为什么不能设置 cols和rows?

TO:hrabeyond
在Html.EditorFor中, new { width="200px",height="150px"} 不起作用。
dingji33 2010-08-12
  • 打赏
  • 举报
回复
哥们。。。仔细看方法签名啊,如果像7楼这样写:

<%= Html.EditorFor(model => model.Content, new { width="200px",height="150px"})%>

对应的方法签名是:

public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression,
Object additionalViewData
)
传送门:http://msdn.microsoft.com/en-us/library/ff406462.aspx

你的第二个参数new { width="200px",height="150px"}对应的是additionalViewData,怎么可能生效?如果你一定要用Html.EditorFor来生成你需要的textarea和样式,这里可以用如下方法:

public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression,
string templateName
)

简要说明一下使用:
假设你是在页面/Views/Student/Edit.aspx上使用Html.EditorFor,那么你可以在Student文件夹下面建一个叫做“EditorTemplates”(文件名固定)的文件夹,里面建一个例如叫area.ascx的控件,内容如下:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<textarea style="width:200px" rows="5">
<%=Model %>
</textarea>

然后在/Views/Student/Edit.aspx上面就可以使用如下:

<%=Html.EditorFor(m=>m.CompanyName,"area") %>


你可以去看看MVC2下面的模板使用,很好很强大
jinseyd 2010-08-11
  • 打赏
  • 举报
回复
Html.EditorFor生成的HTML不是input是textarea 。即使指定CSS样式也不行,
<%: Html.EditorFor(model => model.Content,new {@class="className"})%>
.className{width: 300px;height: 600px;}
毫无作用.
jinseyd 2010-08-11
  • 打赏
  • 举报
回复
走过,路过的朋友帮忙看看~
手抓宝 2010-08-11
  • 打赏
  • 举报
回复
<%= Html.EditorFor(model => model.Content, new { width="200px",height="150px"})%>
dingji33 2010-08-11
  • 打赏
  • 举报
回复
帮你看了下Html.EditorFor的方法签名:
http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor.aspx
其中并没有类似Html.TextAreaFor的Object htmlAttributes参数
我在生成textarea的时候,是这样用的:
<%=Html.TextAreaFor(Model => Model.PrjFundsInfo, new { rows = "8", style = "width:99%" })%>


jinseyd 2010-08-11
  • 打赏
  • 举报
回复
有没有人搞MVC的,帮帮忙啊?

62,241

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧