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>


 

你可能感兴趣的:(html,String,div,actionlink)