部分视图没有转到正确的位置,并且总是打开一个新页面。
我需要在正确的位置(index.cshtml)打开部分视图。如何解决?
public class HomeController : Controller
{
public PartialViewResult LatestNews()
{
var p = new Person();
p.FirstName = " NAME " + DateTime.Now; // To test only
return PartialView("_News", p);
}
索引.cshtml
@Ajax.ActionLink("Click here!", "LatestNews", "Home",
new AjaxOptions { UpdateTargetId = "latestNewsDiv", InsertionMode = InsertionMode.Replace, HttpMethod = "GET", LoadingElementId = "progress" })
<div id="latestNewsDiv">
</div>
<div id="progress">
<p>Loading...</p>
</div>
_News.cshtml
在共享文件夹下
@model MvcApplication1.Models.Person
<h2>News !!!</h2>
<div>
@Model.FirstName
</div>
更新
感谢达林·季米特洛夫
最初我把
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
在HEAD
部分
body
但是当我把它放在标签的底部并且之后@Scripts.Render("~/bundles/jquery")
它工作正常!
@Scripts.Render("~/bundles/jquery")
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
@RenderSection("scripts", required: false)
</body>
</html>