许多时候我们会遇到如下场景在写一个编辑数据的页面时,我们通常会写如下代码1:<inputtype ="text" value='<%=ViewData["title"] %>' name="title" />由前篇我们所讲的Helper演化,我们思考,对于这种代码我们是不是也可以用一个Helper来自动绑定数据呢这当然是可以的,ASP.NET MVC提供了一个HtmlHelper用于生成有数据绑定的Html标签。

1.ActionLink

其中最常用的就是Html.ActionLink
1.1基本的使用方式
1: <%=Html.ActionLink("页面显示的文字", "Index", "Home")%>
在UrlRouting规则为默认规则的情况下,它生成的HTML代码为1:
<a href="/">页面显示的文字</a> ActionLink中的三个参数分别为 (显示的文字 Action Controller)
其中Controller可以省略,省略时指向同一Controller下的Action。

1.2ActionLink中QueryString与Html属性设置
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 { );  //这样操作的话就要指定扩展名(.cshtml)

相关文章:

  • 2021-08-28
  • 2021-05-29
  • 2022-02-24
  • 2022-12-23
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2021-07-06
  • 2021-12-21
相关资源
相似解决方案