Ajax.ActionLink使用方法

来源:互联网 发布:淘宝仓库托管 编辑:程序博客网 时间:2024/06/08 11:10

1. 添加unobtrusive-ajax引用,<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

2. 添加ActionLink

@Ajax.ActionLink("Click here to see today's special", "DailyDeal", new AjaxOptions { UpdateTargetId = "testDiv", InsertionMode = InsertionMode.Replace, HttpMethod = "Get" })


3. 需要添加Controller Action

public ActionResult DailyDeal()        {            ViewBag.Items = new string[] {"AA","BB","CC","DD","EE"};            return PartialView("ViewUserControl1");        }


 

4. 使用ViewUserControl1返回的HTML替换ID=testDiv的HTML元素

<div style="width:100px; background-color:blue; color:white ">        @foreach(var a in ViewBag.Items)    {        @a        <br/>    }</div>


 

原创粉丝点击