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>