asp.net MVC key Tutorial First anniversary edition Nineth back HtmlHelper

Source: Internet
Author: User

Many times we will encounter the following scenario

When writing a page that edits data, we usually write the following code

1: <input type="text" value='<%=ViewData ["title"] %>' name="title" />

By the helper evolution we talked about in the previous article, we thought, would we be able to use a helper to derive data from the binding?

This is certainly possible, ASP.net MVC provides a htmlhelper for generating HTML tags with data binding.

1.ActionLink

One of the most common is html.actionlink.

1.1 Basic ways of using

1: <%=Html.ActionLink("这是一个连接", "Index",  "Home")%>

In the case where the urlrouting rule is the default rule, the HTML code it generates is

1: <a href="/">这是一个连接 </a>

The three parameters in the ActionLink are

Text to display

Action

Controller

Where controller can be omitted, and omitted to point to the action under the same controller.

QueryString and HTML property settings in 1.2ActionLink

1: 带有 QueryString的写法
2: <%=Html.ActionLink("这是一个连接",  "Index", "Home", new { page=1 },null)%>
3: <% =Html.ActionLink("这是一个连接", "Index", new { page=1 })% >
4: 有其它Html属性的写法
5: <%=Html.ActionLink("这是一个连接 ", "Index", "Home", new { id="link1" })% >
6: <%=Html.ActionLink("这是一个连接", "Index",null,  new { id="link1" })%>
7: QueryString与Html属性同时存在
8:  <%=Html.ActionLink("这是一个连接", "Index",  "Home", new { page = 1 }, new { id = "link1" })% >
9: <%=Html.ActionLink("这是一个连接", "Index" ,  new { page = 1 }, new { id = "link1" })%>

The resulting results are:

1: 带有QueryString的写法
2: <a href="/? page=1">这是一个连接</a>
3: <a href="/?page=1">这 是一个连接</a>
4: 有其它Html属性的写法
5: <a href="/? Length=4" id="link1">这是一个连接</a>
6: <a  href="/" id="link1">这是一个连接</a>
7:  QueryString与Html属性同时存在
8: <a href="/?page=1"  id="link1">这是一个连接</a>
9: <a href="/? page=1" id="link1">这是一个连接</a>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.