我正在使用两种模式:
public partial class FORUMTHREAD
{
public FORUMTHREAD()
{
this.FORUMCATEGORY = new HashSet<FORUMCATEGORY>();
this.FORUMPOST = new HashSet<FORUMPOST>();
}
public int TH_ID { get; set; }
public System.DateTime DATE { get; set; }
public string TOPIC { get; set; }
public string USER { get; set; }
public virtual ICollection<FORUMCATEGORY> FORUMCATEGORY { get; set; }
public virtual ICollection<FORUMPOST> FORUMPOST { get; set; }
}
}
public partial class FORUMPOST
{
public FORUMPOST()
{
this.FORUMTHREAD = new HashSet<FORUMTHREAD>();
}
public int PO_ID { get; set; }
public System.DateTime DATE { get; set; }
public string POST { get; set; }
public string USER { get; set; }
public virtual ICollection<FORUMTHREAD> FORUMTHREAD { get; set; }
}
}
我为Create函数创建了视图:
@model AnimeWeb.Models.FORUMTHREAD
@{
ViewBag.Title = "Create";
}
<h2>New Thread</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-field">
@Html.HiddenFor(model => model.TH_ID)
</div>
<div class="editor-label">
TOPIC
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TOPIC)
@Html.ValidationMessageFor(model => model.TOPIC)
</div>
<div class="editor-label">
CATEGORY
</div>
<div class="editor-field">
@Html.DropDownList("Category", Model.GetCategories())
</div>
<div class="editor-label">
POST
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FORUMPOST)
@Html.ValidationMessageFor(model => model.FORUMPOST)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
之后,我在文件夹Shared / EditorTemplates
中创建了FORUMPOST.cshtml作为partialview@model AnimeWeb.Models.FORUMPOST
@Html.HiddenFor(model => model.PO_ID)
@Html.HiddenFor(model => model.USER)
<div>
@Html.TextAreaFor(model => model.POST)
</div>
FORUMPOST的部分视图未呈现。我不知道出了什么问题。我正在使用其他显示/编辑器模板,这些模板工作正常。
编辑:
我还有GENRES EditorTemple可以使用。
GENRES.cshtml
@model AnimeWeb.Models.GENRES
@Html.HiddenFor(model => model.ID_GE)
@Html.HiddenFor(model => model.GENRE)
<table>
<tr>
<td>
@Html.EditorFor(model => model.isSelected)
</td>
<td>
@Html.LabelFor(model => model.isSelected, Model.GENRE)
</td>
</tr>
当我使用@ Html.EditorFor(model =&gt; model.GENRES)渲染它时,它会正确显示。我不想向其他控制器发送垃圾邮件,因此您可以参考我的旧主题here