我有一个强类型的模型 VersaoUpload ,名为索引,此模型有一个成员 IEnumerable ArqUpload ,其中包含两个输入的字段字符串。
视图索引有一个添加动态字段的按钮,当我单击此按钮时,代码呈现一个强类型的 ArqUpload 的部分视图,名为 FileEditBox 以添加字段
但我无法获取动态字段的数据。
查看索引
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<UPDATE.ViewModels.VersaoUpload>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<% using(Html.BeginForm()) { %>
<div id="editorRows">
<% foreach (var item in Model.Arqs)
Html.RenderPartial("FileEditRow", item);
%>
</div>
<%= Html.ActionLink("Add another...", "Add", null, new { id = "addItem" }) %>
<% } %>
</asp:Content>
查看FileEditBox:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<UPDATE.ViewModels.ArqUpload>" %>
<%@ Import Namespace="UPDATE.Helpers"%>
<div class="editorRow">
<% using(Html.BeginCollectionItem("files")) { %>
Arquivo: <%= Html.FileBoxFor(x => x.Arquivo) %>
Tipo:
<%=Html.RadioButtonFor(x => x.Tipo,"1")%> Sql
<%=Html.RadioButtonFor(x => x.Tipo,"2")%> Package
<%=Html.RadioButtonFor(x => x.Tipo,"3")%> Config
<a href="#" class="deleteRow">delete</a>
<% } %>
</div>
控制器:
public ViewResult Add()
{
return View("FileEditRow", new ArqUpload());
}
[HttpPost]
public ActionResult Index(VersaoUpload versao)
{
// To do: do whatever you want with the data
return View("Resultado",versao);
}
这是查看结果的Resultado视图:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<UPDATE.ViewModels.VersaoUpload>" %>
<% foreach (ArqUpload it in Model.Arqs)
{ %>
<div class="display-label">Tipo Arquvo</div>
<div class="display-field"><%: it.Tipo %></div>
<% } %>
但是,it.Tipo为空。