自定义编辑器模板无效

时间:2014-10-27 17:40:24

标签: asp.net asp.net-mvc asp.net-mvc-3 templates mvc-editor-templates

我有模特的集合。对于该集合中的每个项目,我需要呈现一些html表单。所以我决定为这个模型创建编辑器模板。

这就像我“调用”我的编辑器模板。

<% for (int i = 0; i < Model.SpaceImages.Count; i++)
                           { %>
                        <% Html.EditorFor(m => m.SpaceImages[i]); %>
                        <% } %>

这是我的模板:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.Application.ListingSpaceAttachmentModel>" %>
<%@ Import Namespace="Web.Extensions" %>

<div id="SpaceImagesControl" class="attachment-upload-control">
    <input type="hidden" class="attachment-type" value="image" />
    <input type="hidden" class="is-dynamic-attachment-list" value="true" />
    <div class="form-field uploader-field">
        <div id="listingSpaceImagesUploader" class="attachment-uploader" style="margin-left: 60px;">
            <button class="upload-btn btn-sm"><strong>Add</strong></button>
        </div>
    </div>
    <div class="uploader-data-section">
        <input class="base-attachment-src" type="hidden" />
        <input class="base-preview-attachment-src" type="hidden" />
        <input class="attachment-src" type="hidden" />
        <input class="img-width" type="hidden" />
        <input class="img-height" type="hidden" />
        <input class="img-ratio" type="hidden" />
    </div>
    <div class="attachment-data-section">
        <%:Html.HiddenFor(m => m.AttachmentId) %>
        <%:Html.HiddenFor(m => m.AttachmentType) %>
        <%:Html.HiddenFor(m => m.OrdinalNumber) %>
        <%:Html.HiddenFor(m => m.AttachmentTitle, new {@class="attachment-title-input"}) %>
        <%:Html.HiddenFor(m => m.AttachmentPath, new {@class="attachment-input"}) %>
        <%:Html.HiddenFor(m => m.AttachmentOriginalPath, new {@class="attachment-original-input"}) %>
    </div>
    <div class="attachment-container-template" style="display: none;">

        <div class="attachmentLoadContainer imgLoadContainer">
            <input type="hidden" class="attachment-input-name" value="AttachmentName" />
            <input type="hidden" class="attachment-original-input-name" value="AttachmentOrigName" />
            <input type="hidden" class="attachment-title-input-name" value="AttachmentTitle" />
            <div class="attachment-control image-control">
                <span>
                    <a class="delete-attachment-btn delete-image-btn" href="#">&nbsp;</a>
                    <a class="set-main-attachment-btn set-main-image-btn" href="#" %>">&nbsp;</a>
                    <a class="preview-attachment-btn preview-image-btn" href="#"%>">&nbsp;</a>
                </span>
                <a class="attachment-thumbnail image-thumbnail" href="JavaScript: return false;">
                    <img alt="ImageName" src="" /></a>
            </div>
        </div>
    </div>
    <div class="attachment-section photo-section">
    </div>
</div>

当我运行我的webApp时,我发现在编辑器模板html必须存在的地方没有任何渲染。我在调试模式下检查它 - 它通过编辑器模板。不知道为什么没有。


更新:

正如@Stephen所说,我尝试更新我的编辑器以采取'收集'来防止重复的id。 所以我添加模型

public class AttachmentsModel
    {
        public AttachmentsModel()
        {
            AttachmentList = new List<ListingAttachmentModel>();
        }

        public IList<ListingAttachmentModel> AttachmentList { get; set; }
    }

包含元素列表,现在我将它传递给编辑器。但是从编辑那里得到: System.Collections.Generic.List'1[Models.Application.ListingAttachmentModel]

之前不知道为什么我做类似的事情

0 个答案:

没有答案