我正在尝试使用以下内容在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>
Run Code Online (Sandbox Code Playgroud)
在BookController中:
public ActionResult BargainBook()
{
var book = GetBargainBook();
return PartialView("_BargainBook", book);
}
private Book GetBargainBook()
{
return db.Books
.OrderBy(b => b.Price)
.First();
Run Code Online (Sandbox Code Playgroud)
}
在_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>
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,我会转到部分页面数据的完整页面视图.
Ada*_*SFT 12
关于让这个工作的另一个注意事项.我希望VS 2013 RTM包含这个,但无论哪种方式,这都应该让你开始运行
install-package Microsoft.jQuery.Ajax.Unobtrusive
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*")
);
@Scripts.Render("~/bundles/jquery")
或将其包含在您要使用它的每个视图中
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
| 归档时间: |
|
| 查看次数: |
7499 次 |
| 最近记录: |