如何创建视图以将新项目添加到视图模型中的列表?
所以我有一个包含对象列表的视图模型(视图模型中还有另一个对象)。基本上列表将是评论(所以我可能有零到 x 条评论)。
我正在使用 VS 2010(我不认为它是剃刀视图引擎?)
这是我的观点,我希望可以选择将新项目添加到列表中
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<JPROCommunitydataListings.ViewModels.dataWithCommentsViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
data Solution
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p>data Description# <%: Model.data.Description %></p>
<p>data ParameterID# <%: Model.data.ParameterID %></p>
<%--<h2>dataWithComments</h2>--%>
<table class="table table-striped table-hover">
<tr>
<th>
Comment
</th>
</tr>
<% foreach (var Comment in Model.Comments) { %>
<td>
<%: Comment.comment1%>
</td>
<% } %>
</table>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Add Comment</legend>
<div class="editor-label">
<"label">
What to do here????????
<%--<%: Html.LabelFor(model => model.Comments[0].comment1) %>--%>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Comments.comment1)%>
<%: Html.ValidationMessageFor(model => model.Comments[0].comment1)%>
</div>
What to do here????????
<p>
<input type="submit" value="Search" />
</p>
</fieldset>
<% } %>
</fieldset>
<p>
<%: Html.ActionLink("Search", "Search") %>
</p>
</asp:Content>