zoukankan      html  css  js  c++  java
  • Ajax.ActionLink参数详解

    原文:http://www.cnblogs.com/zzgblog/p/5454025.html

    该语法会生成一个a标签,点击a标签会执行一个Ajax请求。

    12个方法重载,下面详解方法中的各项参数:

    参数一:linkText

    string类型

    说明:链接显示的文字内容

    参数二:actionName

    string类型

    说明:指定请求地址的Action名称

    参数三:ajaxOptions

    class类型

    说明:配置Ajax的一些选项

    举例:new AjaxOptions { HttpMethod = "POST", LoadingElementId = "searching", UpdateTargetId = "postContent" }

    相关属性详解:

    Confirm

    string

    在请求之前会弹出一个提示框,是否确认提交

    HttpMethod

    string

    设置请求类型 Get Post

    UpdateTargetId

    String

    标明html中一元素的id,把请求返回的数据/元素更新到该元素中

    InsertionMode

    enum

    把请求结果以何种方式更新到Dom元素中

    ①Replace

    ②InsertBefore

    ③InsertAfter

    不设置的情况下,默认是Replace,只有在UpdateTargetId被设置后才有效

    LoadingElementId

    string

    标明html中一元素的id,在请求过程中,该元素会显示出来,请求结束后又隐藏

    LoadingElementDuration

    Int

    控制Loading动画在显示/隐藏时的动画持续时间,单位为毫秒;

    默认情况下,动画将淡入淡出;这个时间即淡入淡出的时间(但经测试无效!!!)

    OnBegin

    string

    标明js中一function的名称,在Ajax请求发送前,执行该方法,对应JQuerybeforeSend

    OnComplete

    String

    标明js中一function的名称,在请求成功时,执行该方法,对应JQuerycomplete

    OnFailure

    String

    标明js中一function的名称,在请求失败时,执行该方法,对应JQueryerror

    OnSuccess

    String

    标明js中一function的名称,无论请求成功与否,都在请求完成时,执行该方法,对应JQuerysuccess

    Url

    String

    请求的地址

    AllowCache

    Bool

    是否使用缓存

    BeginForm11个重载方法中,有一方法中只有AjaxOptions一个参数,如果不指定Url,则生成的form表单的action属性没有值,就默认把数据提交到当前页,否则就以Url为请求地址,其他重载方法中都需要指定actionName及controllerName(可选)。

    参数四:routeValues

    object、RouteValueDictionary类型

    说明:将传入到Controller中方法的参数

    支持上述两种数据类型:

    object类型可以在使用时直接以匿名类方式声明,使用非常方便

    举例:

    new { id = 1, type = 1 }

    RouteValueDictionary类型实现了IDictionary<string, object>接口,因此在使用时可以用键值对方式声明

    举例:

    new RouteValueDictionary{ {"id", 1}, {"type", 1} }

    生成的路径:/Home/Index/1?type=1

    因为“id”是在路由规则中配置的名称,因此显示在路由规则对应的位置,“type”则在问号后面

    参数五:htmlAttributes

    object、IDictionary<string, object>类型

    说明:html属性,生成form表单时,会把键值对添加到form表单的属性中;

    支持上述两种数据类型:

    object类型可以在使用时直接以匿名类方式声明,使用非常方便

    举例:

    new{id = "frm", @class = "cls" }    由于classC#中的关键字,因此需要在前面加@符号

    IDictionary<string, object>类型使用灵活,可以在一个地方声明,多个地方调用,或修改后使用

    举例:

    Dictionary<string, object> htmlAttr = new Dictionary<string, object>

     {

         {"id", "frm"},

         {"class", "cls"}

     };   

    生成的代码:<form action="/Home/Index/1?type=1" class="cls" data-ajax="true" id="frm" method="post">

    参数六:controllerName

    string类型

    说明:指定请求地址的Controller名称

    参数七:protocol

    string类型

    说明:指定链接的协议类型,比如httphttps

    参数八:hostName

    string类型

    说明:指定链接的主机地址,可以有域名+端口号,比如ayilaile.com:80

    参数九:fragment

    string类型

    说明:指定链接中的锚点名称

    七、八、九三个参数的重载方法很少使用

    示例:

    @Ajax.ActionLink("ActionLink", "Index", "Home", "https", "www.ayilaile.com:90", "title", new { id = 1, type = 1 }, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "detailsID", InsertionMode = InsertionMode.Replace }, new{ id = "testid"})

    生成的链接为:https://www.ayilaile.com:90/Home/Index/1?type=1#title

  • 相关阅读:
    leetcode 18 4Sum
    leetcode 71 Simplify Path
    leetcode 10 Regular Expression Matching
    leetcode 30 Substring with Concatenation of All Words
    leetcode 355 Design Twitte
    leetcode LRU Cache
    leetcode 3Sum
    leetcode Letter Combinations of a Phone Number
    leetcode Remove Nth Node From End of List
    leetcode Valid Parentheses
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/5783673.html
Copyright © 2011-2022 走看看