MVC3----輔助方法的使用

來源:互聯網
上載者:User

標籤:關鍵字   hello   style   標籤   

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>


==================添加輸入元素

[email protected]

@Html.TextBox("Title", string.Empty)//單行輸入

產生標籤:

<input id="Title" name="Title" type="text" value="" />


[email protected]

@Html.TextArea("Title", string.Empty)//多行輸入

產生標籤:

<textarea cols="20" id="Title" name="Title" rows="2">


[email protected]

@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"))

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/54/68/wKiom1SBVivyf9EsAAAMT2-8rBs194.jpg" title="搜狗20141205145501.png" alt="wKiom1SBVivyf9EsAAAMT2-8rBs194.jpg" />


控制器代碼:

//                                  集合 ,值欄位,文字欄位,選定的值ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);


視圖代碼:







本文出自 “程式猿的家--Hunter” 部落格,請務必保留此出處http://962410314.blog.51cto.com/7563109/1586703

MVC3----輔助方法的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.