现在的位置: 首页 > 综合 > 正文

MVC中使用AJAX方式调用数据(microsoft,jquery两种方式)

2013年07月22日 ⁄ 综合 ⁄ 共 1241字 ⁄ 字号 评论关闭

HTML 中

 

<% =Ajax.ActionLink("AJAX调用", "AjaxByJquery", new { name = "tttt" }, new AjaxOptions { LoadingElementId = "Loading", UpdateTargetId = "jqueryResult", InsertionMode = InsertionMode.InsertAfter })%>

 

显示结果与进度的HTML代码,与上面的代码放在同一个文件中

 <div id="loading">loading.......</div>
 <div id="result"></div>
<div id="jqueryResult"></div>

 

 

如果是jquery,用如下脚本:

 

 

js引用

<script src="../../Scripts/jquery-1.3.1-vsdoc.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

 

 

 

Controlls中的代码

 

 public ActionResult AjaxByJquery(String name)
        {
            ViewData["ajaxHello"] = name;
            return View("ajaxContent");
        }

 

 

ajaxContent.ascx的HTML代码,将控件的代码插入到result标签中,完成结果显示

 

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% = Html.Encode(ViewData["ajaxHello"]) %>

 

 

抱歉!评论已关闭.