Asp.Net Mvc 之AjaxHelper

正文:

    除了HtmlHelper之外,还有UrlHelper帮助方法:

     1.@Url.Action():url字符串

     <a href="@Url.Action("Index", "Home", new { id = 100 })">跳转</a><br />

     2.@Url.RouteUrl:根据路由名称生成url字符串

     @Url.RouteUrl("Default1", new { controller = "Home", action = "index", id = 100, name = "abc" });

     3.@Url.RouteCollection.GetRouteData():得到RouteData(键值对)数据(控制器,action,参数)

      @{
            var routdata = Url.RouteCollection.GetRouteData(new HttpContextWrapper(HttpContext.Current));
            var list = routdata.Values.ToList();
            foreach (var item in list)
            {
                   @item.Key @:----
                   @item.Value             
            }
        }

     AjaxHelper帮助方法:

      1.@Ajax.ActionLink():(下面有AjaxOptions图)

      @Ajax.ActionLink("显示字符串", "ActionName", "ControllerName", new AjaxOptions()
     {
      Confirm="是否要发出请求?",
       Url = Url.Action("ActionName", "ControllerName")
       ,
       HttpMethod = "post"
       ,
       UpdateTargetId = "displayDiv" //更新的html元素id
      ,
       InsertionMode = InsertionMode.Replace //更新方式
       ,
       LoadingElementId = "loading"//加载时显示的元素id
       ,
       OnSuccess = "success"   
       ,
       OnBegin = "begin"
       ,
       OnFailure = "fail"
       ,
       OnComplete = "comp" //完成时触发
   });

    

       2.@Ajax.BeginForm():参数与@Ajax.ActionLink()同理(下面有AjaxOptions图)

   

     

         其中AjaxOptions:

        

        使用AJax进行编辑小Demo:

   

    

        引入脚本:

     

   

        后台控制器再次验证以及编辑操作:

   

          同样的webconfig文件需要确认:

    

 

 

 

 

 

 

END

posted on 2015-09-07 19:10  巴夫巴夫  阅读(477)  评论(0编辑  收藏  举报