Ajax.ActionLink使用方法

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>


 

發佈了257 篇原創文章 · 獲贊 6 · 訪問量 31萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章