我是MVC的新手。使用MVC 3.MVC局部視圖隱藏主視圖
我有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動作鏈接。那麼,錯誤在哪裏?
它顯示了網格insi de plain page ...它不會顯示頂部鏈接應用程序名稱和所有... – 2012-04-18 12:24:35
您是否嘗試將此與Eray所說的相結合,並在部分視圖頂部設置Layout = null? – mattytommo 2012-04-18 12:26:56
是的..請參閱評論...也行動鏈接不顯示我想要顯示在網格上面。 – 2012-04-18 12:31:08