我是 MVC 的新手。使用 MVC 3。
我有如下的 PersonMaster 控制器...具有以下两个操作。
public ActionResult TopTenPersons()
{
Thread.Sleep(2000);
var persons = DatabaseHelper.Instance.Database.Query<Person_Master>("select top(10) from person_master").ToList();
return View("_PersonGrid", persons);
}
public ActionResult Index()
{
var persons = DatabaseHelper.Instance.Database.Query<Person_Master>("select * from person_master").ToList();
return View("_PersonGrid",persons);
//return View();
}
然后,index.cshtml 视图如下..
@model System.Collections.Generic.ICollection<MyPracticeApp1.Models.Person_Master>
@section scripts{
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
}
<h2>Persons</h2>
<p>
@Ajax.ActionLink("Click to top 10 Persons","TopTenPersons", new AjaxOptions{
UpdateTargetId="tbl_person",
InsertionMode=InsertionMode.Replace,
HttpMethod="GET"
})
</p>
<div id="tbl_person">
@Html.Action("Index","PersonMaster");
</div>
..和上面在索引视图中调用的部分视图_PersonGrid.cshtml如下......
@model System.Collections.Generic.ICollection<MyPracticeApp1.Models.Person_Master>
@{
var persongrid = new WebGrid(Model);
}
@persongrid.GetHtml()
....但问题是它直接显示部分视图。它没有呈现索引视图的 Ajax Actionlink。那么,错在哪里呢?