Use:
<script src="@Url.Content("~/Scripts/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<div id="dailydeal"> @Ajax.ActionLink("Click here to see today's special!", "DailyDeal", new AjaxOptions{ UpdateTargetId = "dailydeal", InsertionMode = InsertionMode.InsertAfter, HttpMethod = "GETS", Confirm = "Are you sure?" }); </div>
insertionMode有insertAfter,replace,insertBefore. @Ajax.ActionLink有 handling errors, displaying a loading element, displaying a confi rmation dialog, and....
The second parameter is ActionName。
public ActionResult DailyDeal() { ViewBag.message = "This is daily deal message"; return PartialView(); }
新建一个DailyDeal.cshtml
Ajax.BeginForm
@using (Ajax.BeginForm("searchAction", new AjaxOptions { HttpMethod="GET",InsertionMode =InsertionMode.Replace, OnFailure="searchFailed",LoadingElementId="ajax-loader", UpdateTargetId="searchresults" })) { <input type="text" name="q" /> <input type="submit" value="search" /> <img id="ajax-loader" src="@Url.Content("~/images/1.gif")" style="display:none" /> } <script type="text/javascript"> function searchFailed() { alert("search failed."); } </script>