最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET MVC - HTML 幫助器

HTML 幫助器用于修改 HTML 輸出。

HTML 幫助器

通過(guò) MVC,HTML 幫助器類似于傳統(tǒng)的 ASP.NET Web Form 控件。

類似 ASP.NET 中的 web form 控件,HTML 幫助器用于修改 HTML。但是 HTML 幫助器更輕。與 web form 控件不同,HTML 幫助器沒有事件模型和 view state。

在大多數(shù)情況下,HTML 幫助器僅僅是返回字符串的方法。

通過(guò) MVC,您能夠創(chuàng)建自己的幫助器,或者使用內(nèi)建的 HTML 幫助器。

標(biāo)準(zhǔn)的 HTML 幫助器

MVC 包含了大多數(shù)常用的 HTML 元素類型的標(biāo)準(zhǔn)幫助器,比如 HTML 鏈接和 HTML 表單元素。

HTML 鏈接

呈現(xiàn) HTML 鏈接的最簡(jiǎn)單方法是使用 HTML.ActionLink() 幫助器。

通過(guò) MVC,Html.ActionLink() 不連接到視圖。它創(chuàng)建控制器操作(controller action)的連接。

Razor 語(yǔ)法:

@Html.ActionLink("About this Website", "About")

ASP 語(yǔ)法:

<%=Html.ActionLink("About this Website", "About")%>

第一個(gè)參數(shù)是鏈接文本,第二個(gè)參數(shù)是控制器操作的名稱。

上面的 Html.ActionLink() 幫助器,輸出以下 HTML:

<a href="/Home/About">About this Website</a>

Html.ActionLink() 幫助器的若干參數(shù):

參數(shù) 描述
linkText 定位點(diǎn)元素的內(nèi)部文本。
actionName 操作的名稱。
controllerName 控制器的名稱。
protocol URL 協(xié)議,如“http”或“https”。
hostname URL 的主機(jī)名。
fragment URL 片段名稱(定位點(diǎn)名稱)。
routeValues 一個(gè)包含路由參數(shù)的對(duì)象。
htmlAttributes 一個(gè)對(duì)象,包含要為該元素設(shè)置的 HTML 特性。

注釋:您可以向控制器操作傳遞值。例如,您能夠像數(shù)據(jù)庫(kù)編輯操作傳遞數(shù)據(jù)庫(kù)記錄的 id。

Razor 語(yǔ)法 C#:

@Html.ActionLink("Edit Record", "Edit", new {Id=3})

Razor 語(yǔ)法 VB:

@Html.ActionLink("Edit Record", "Edit", New With{.Id=3})

上面的 Html.ActionLink() 幫助器,輸出以下 HTML:

<a href="/Home/Edit/3">Edit Record</a>

HTML 表單元素

以下 HTML 幫助器可用于呈現(xiàn)(修改和輸出)HTML 表單元素:

  • BeginForm()
  • EndForm()
  • TextArea()
  • TextBox()
  • CheckBox()
  • RadioButton()
  • ListBox()
  • DropDownList()
  • Hidden()
  • Password()

ASP.NET 語(yǔ)法 C#:

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and 
try again.") %>
<% using (Html.BeginForm()){%>
<p>
<label for="FirstName">First Name:</label>
<%= Html.TextBox("FirstName") %>
<%= Html.ValidationMessage("FirstName", "*") %>
</p>
<p>
<label for="LastName">Last Name:</label>
<%= Html.TextBox("LastName") %>
<%= Html.ValidationMessage("LastName", "*") %>
</p>
<p>
<label for="Password">Password:</label>
<%= Html.Password("Password") %>
<%= Html.ValidationMessage("Password", "*") %>
</p>
<p>
<label for="Password">Confirm Password:</label>
<%= Html.Password("ConfirmPassword") %>
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
</p>
<p>
<label for="Profile">Profile:</label>
<%= Html.TextArea("Profile", new {cols=60, rows=10})%>
</p>
<p>
<%= Html.CheckBox("ReceiveNewsletter") %>
<label for="ReceiveNewsletter" style="display:inline">Receive Newsletter?</label>
</p>
<p>
<input type="submit" value="Register" />
</p>
<%}%>
四川省| 子洲县| 仁寿县| 习水县| 墨江| 汝城县| 文成县| 汉源县| 肥城市| 大同市| 临夏市| 连云港市| 财经| 靖西县| 类乌齐县| 惠来县| 三原县| 静宁县| 和龙市| 新密市| 饶平县| 固镇县| 陆良县| 浪卡子县| 班戈县| 杨浦区| 洛扎县| 新丰县| 巩义市| 富平县| 江西省| 潜山县| 盖州市| 临桂县| 莱阳市| 常山县| 年辖:市辖区| 青铜峡市| 额尔古纳市| 朔州市| 孟津县|