我正在使用以下内容在ASP.Net MVC 5(Visual Studio 13)中替换部分视图的一部分页面:
查看/预订/ Index.cshtml:
<div id="bargainBook"> @Ajax.ActionLink("Click here for the Bargain Book!","BargainBook",new AjaxOptions { UpdateTargetId = "bargainBook",InsertionMode = InsertionMode.Replace,HttpMethod = "GET" }) </div>
在BookController中:
public ActionResult BargainBook() { var book = GetBargainBook(); return PartialView("_BargainBook",book); } private Book GetBargainBook() { return db.Books .OrderBy(b => b.Price) .First();
}
在_BargainBook.cshtml中:
@model BookDemo.Models.Book <div> <p> <strong>Book</strong> @Model.Name </p> <p> <strong>Price</strong> @String.Format("{0:F}",@Model.Price) </p> </div>