zoukankan      html  css  js  c++  java
  • ASP.NET MVC4 View层_Razor操作Html元素

    1 常用 Html 标签

    1.1 Label

    Html 语法 :<label for="UserName">用户名</label>

    Razor语法@Html.LabelFor(m => m.UserName)

    1.2 <input type="text" />

    Html 语法

    <input  id=" UserName " name=" UserName " type=" text " value="" />

    Razor语法: 
    @Html.TextBoxFor(m => m.UserName)

    1.3 <input type="hidden" />

    Html 语法

    <input id=" UserName " name=" UserName " type="hidden" value="" />

    Razor语法: 
    @Html.TextBoxFor(m => m.UserName)

    1.4 <input type="password" />标签

    Html 语法

    <input id="UserPass" name="UserPass" type="PasswordFor" value="" />

    Razor语法: 
    @Html.PasswordFor(m => m.UserPass)

    1.5 <input type="radio" />标签

    Html 语法

    <input id="Sex0" name="Sex" type="radio" value="0" /> 男
    <input id="Sex1" name="Sex" type="radio" value="1" /> 女
    <input id="Sex2" name="Sex" type="radio" value="2" /> 保密
    Razor语法: 

    @ Html .RadioButtonFor(m=> m.Sex, 0, new { @id = "Sex0"}) 男

    @ Html .RadioButtonFor(m=> m.Sex, 1, new { @id = "Sex1"}) 女

    @ Html .RadioButtonFor(m=> m.Sex, 2, new { @id = "Sex2"}) 保密

    1.6 <input type="checkbox" />标签

    Html 语法

    <input id="RememberMe" name="RememberMe" type="checkbox" value="true" />
    Razor语法: 
    @Html.PasswordFor(m => m.UserPass)

    2 链接地址

    @Url.Content()

    @Url.Action

    2.1 引用CSS样式文件

    Html 语法

    <link href="/Content/style.css" />
    Razor语法: 
    <link href="@Url.Content("~/Content/style.css")" />

    2.2 引用Javascript文件

    Html 语法

    <script src="/Content/jquery.js"></script>
    Razor语法: 
    <script src="@Url.Content("~/Content/jquery.js")"></script>

    2.3 Image引用图片文件

    Html 语法

    <img src="/Content/images/1.jpg" />
    Razor语法: 
    <script src="@Url.Content("~/Content/images/1.jpg")"></script>

    2.4 超链接

    Html 语法

    <a href="/Register">注册</a>
    Razor语法: 
    @Html.ActionLink("注册", "Register")
    注:@Html.ActionLink有多个重载,具体参照MSDN API文档

    3 表单

    3.1 正常提交表单

    @using( Html .BeginForm()){

    //默认提交到本页面

    <input type="submit" value="Button"/>

    }

    3.2 Ajax提交表单

    @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId="txtResult" }))
    {
            <input type="submit" value="Button"/>            
            <span id="txtResult"/>

  • 相关阅读:
    json解析:[1]gson解析json
    android 调用系统相机拍照 获取原图
    EventBus使用详解(二)——EventBus使用进阶
    java中的正则表达式
    java的UI设计--------------------------------待补充
    java的网络编程
    IO知识点整理(序列化,管道流,数据流,字节数组流,与编码)
    IO知识点整理(文件File类的使用)
    040 DataFrame中的write与read编程
    039 DataFrame的理解
  • 原文地址:https://www.cnblogs.com/TF12138/p/4115169.html
Copyright © 2011-2022 走看看