1,
@Html.TextBox("txt", "hello", new { style = "width:1000px;height:1000px;" })
生成标签:
<input id="txt" name="txt" style="width:1000px;height:1000px;" type="text" value="hello" />
2,
特殊属性(class:c#保留关键字)
@Html.TextBox("txt", "hello", new { style = "width:1000px;height:1000px;",@class="aa" })
生成标签:
<input class="aa" id="txt" name="txt" style="width:1000px;height:1000px;" type="text" value="hello" />
3,
带连接字符的属性(例如:data_result)
@Html.TextArea("text", "hello", new { data_result ="data"})
生成标签:
<textarea cols="20" data-result="data" id="text" name="text" rows="2">hello</textarea>
4,
@using (Html.BeginForm()) { <input type="submit" value="Create" /> }
生成标签:
<form action="/storemanager" method="post">
<input type="submit" value="Create" />
</form>
==================添加输入元素
----@Html.TextBox
@Html.TextBox("Title", string.Empty) //单行输入
生成标签:
<input id="Title" name="Title" type="text" value="" />
----@Html.TextArea
@Html.TextArea("Title", string.Empty) //多行输入
生成标签:
<textarea cols="20" id="Title" name="Title" rows="2">
----@Html.Label
@Html.Label("Title","请输入:")
生成标签:
<label for="Title">请输入:</label>
---- @Html.ListBox(可以多项选择)
@{ List<string> listbox = new List<string>(); listbox.Add("a"); listbox.Add("b"); listbox.Add("c"); } @Html.ListBox("listitem", new SelectList(listbox,"a"))
控制器代码:
// 集合 ,值字段,文本字段,选定的值 ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
视图代码:
本文出自 “程序猿的家--Hunter” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1586703
原文地址:http://962410314.blog.51cto.com/7563109/1586703