1

我有一个名为index的模型VersaoUpload的强类型视图,该模型有一个成员IEnumerable ArqUpload,其中包含两个字段类型为字符串。

视图索引有一个添加动态字段的按钮,当我点击这个按钮时,代码会渲染一个名为FileEditBox的局部视图强类型ArqUpload来添加字段。

但我没有得到动态字段的数据。

查看索引

<%@ 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>

查看文件编辑框:

<%@ 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 为空。

4

0 回答 0