View 不显示数据的局部视图
我有一个不显示数据的局部视图。这是一个简单的版本。这是我的模型。父记录和子记录View 不显示数据的局部视图,view,partial,View,Partial,我有一个不显示数据的局部视图。这是一个简单的版本。这是我的模型。父记录和子记录 namespace Partial.Models { using System; using System.Collections.Generic; public partial class Parent { [System.Diagnostics.CodeAnalysis.SuppressMessage ("Microsoft.Usage", "CA2214
namespace Partial.Models
{
using System;
using System.Collections.Generic;
public partial class Parent
{
[System.Diagnostics.CodeAnalysis.SuppressMessage ("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Parent()
{
this.Children = new HashSet<Child>();
}
public int ID { get; set; }
public string Description { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Child> Children { get; set; }
}
}
namespace Partial.Models
{
using System;
using System.Collections.Generic;
public partial class Child
{
public int ID { get; set; }
public Nullable<int> ParentID { get; set; }
public string Description { get; set; }
public virtual Parent Parent { get; set; }
}
}
这是我的看法。作为编辑表单的父表单。哪个应该显示子索引窗体
@model Partial.Models.Parent
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
<div class="form-horizontal">
<h4>Parent</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<table class="table">
<tr>
<td>
Html.Partial("~/Views/Children/Index.cshtml", new List<Partial.Models.Child> ());
</td>
</tr>
</table>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
应显示子项但不显示子项的子窗体
@model IEnumerable<Partial.Models.Child>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Parent.Description)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Parent.Description)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
删除代码
Html.Partial("~/Views/Children/Index.cshtml", new List<Partial.Models.Child> ());
对这个问题进行更多的上下文分析将有助于准确地找出问题的症结所在。您还想看到什么?
Please Try Code
Html.Partial("~/Views/Children/Index.cshtml", new List<Partial.Models.Child> ());
Sysntext For :
@Html.RenderAction("Action name","Controller name",Route values)