zoukankan      html  css  js  c++  java
  • ASP.NET MVC HtmlHelper用法大全

    HTML扩展类的所有方法都有2个参数:
    
    以textbox为例子
    
    public static string TextBox( this HtmlHelper htmlHelper, string name, Object value,IDictionary<string, Object> htmlAttributes )
    
    public static string TextBox( this HtmlHelper htmlHelper, string name, Object value, Object htmlAttributes )
    
    这2个参数代表这个html标签的属性集合。使用方法如下。
    
     
    
    1.ActionLink
    
    <%=Html.ActionLink("这是一个连接", "Index", "Home")%>
    带有QueryString的写法
    <%=Html.ActionLink("这是一个连接", "Index", "Home", new { page=1 },null)%>
    <%=Html.ActionLink("这是一个连接", "Index", new { page=1 })%>
    有其它Html属性的写法
    <%=Html.ActionLink("这是一个连接", "Index", "Home", new { id="link1" })%>
    <%=Html.ActionLink("这是一个连接", "Index",null, new { id="link1" })%>
    QueryString与Html属性同时存在
    <%=Html.ActionLink("这是一个连接", "Index", "Home", new { page = 1 }, new { id = "link1" })%>
    <%=Html.ActionLink("这是一个连接", "Index" , new { page = 1 }, new { id = "link1" })%>
     
    生成结果为:
    <a href="/">这是一个连接</a>
    带有QueryString的写法
    <a href="/?page=1">这是一个连接</a>
    <a href="/?page=1">这是一个连接</a>
    有其它Html属性的写法
    <a href="/?Length=4" id="link1">这是一个连接</a>
    <a href="/" id="link1">这是一个连接</a>
    QueryString与Html属性同时存在
    <a href="/?page=1" id="link1">这是一个连接</a>
    <a href="/?page=1" id="link1">这是一个连接</a>
     
    2.RouteLink
    
    跟ActionLink在功能上一样。
    <%=Html.RouteLink("关于", "about", new { })%>
    带QueryString
    <%=Html.RouteLink("关于", "about", new { page = 1 })%>
    <%=Html.RouteLink("关于", "about", new { page = 1 }, new { id = "link1" })%>
     
    生成结果:
    <a href="/about">关于</a>
    <a href="/about?page=1">关于</a>
    <a href="/about?page=1" id="link1">关于</a>
    3.Form   2种方法
    
    <%using(Html.BeginForm("index","home",FormMethod.Post)){%>
    <%} %>
     
    <%Html.BeginForm("index", "home", FormMethod.Post);//注意这里没有=输出%>
    <%Html.EndForm(); %>
     
    生成结果:
    <form action="/home/index" method="post"></form>
     
    
    4.TextBox , Hidden ,
    
    <%=Html.TextBox("input1") %>
    <%=Html.TextBox("input2",Model.CategoryName,new{ @style = "300px;" }) %>
    <%=Html.TextBox("input3", ViewData["Name"],new{ @style = "300px;" }) %>
    <%=Html.TextBoxFor(a => a.CategoryName, new { @style = "300px;" })%>
     
    生成结果:
     
    <input id="input1" name="input1" type="text" value="" />
    <input id="input2" name="input2" style="300px;" type="text" value="Beverages" />
    <input id="input3" name="input3" style="300px;" type="text" value="" />
    <input id="CategoryName" name="CategoryName" style="300px;" type="text" value="Beverages" />
     
    
    5.TextArea
    
    <%=Html.TextArea("input5", Model.CategoryName, 3, 9,null)%>
    <%=Html.TextAreaFor(a => a.CategoryName, 3, 3, null)%>
     
    生成结果:
    <textarea cols="9" id="input5" name="input5" rows="3">Beverages</textarea>
    <textarea cols="3" id="CategoryName" name="CategoryName" rows="3">Beverages</textarea>
  • 相关阅读:
    bug的生命周期
    性能测试的流程
    通过画因果图来写测试用例的步骤为___、___、___、___及把因果图转换为状态图共五个步骤。&#160;利用因果图生成测试用例的基本步骤是:
    集成测试中自顶向下集成和自底向上集成两个策略的理解,要谈出它们各自的优缺点和主要适应于哪种类型测试;
    Spring中的八大设计模式
    ssh
    window实用快捷键-win篇
    解决Chrome浏览器“崩溃啦”的问题!
    C语言-格式输出
    AIDA64+RemotePanel 组副屏电脑状态监视器 旧手机废物利用 wifi/数据线 adb驱动
  • 原文地址:https://www.cnblogs.com/cyccess/p/3081821.html
Copyright © 2011-2022 走看看