ASP.NET MVC 4 View ( Razor ) + AjaxHelper – ActionLink + Partial View ( Parameter ) 使用方法 I
web.config |
<configuration> … … <appSettings> … … <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> … … </configuration> |
App_Start\BundleConfig.cs |
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery.unobtrusive-ajax.js")); |
Controller |
public ActionResult View1(int id) { ViewBag.Content = id.ToString(); return PartialView(); } |
View |
@Ajax.ActionLink("Link 1", "View1", new { id = 1 }, new AjaxOptions { UpdateTargetId = "Panel" }) @Ajax.ActionLink("Link 2", "View1", new { id = 2 }, new AjaxOptions { UpdateTargetId = "Panel" }) <div id="Panel"></div> |
View1.cshtml |
@ViewBag.Content |