无法生成用于文件上传的支架 [英] Couldn't generate scaffold for file upload

查看:71
本文介绍了无法生成用于文件上传的支架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为文件上传生成视图,但是缺少上传部分,其余的班级成员都为他们生成了视图

I tried to generate a view for file upload but the upload part was missing and the rest class members have view generated for them

查看模型

namespace myapps.Models.ViewModels
{
    public class UserPhotoUploadViewModel
    {

        public HttpPostedFile PhotoFile
        {
            get;
            set;
        }

        public Guid UserID
        {
            get;
            set;
        }
    }
}

生成的视图

@model myapps.Models.ViewModels.UserPhotoUploadViewModel

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>UserPhotoUploadModel</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserID)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserID)
            @Html.ValidationMessageFor(model => model.UserID)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

我是否希望填写其余内容?这是通常的行为,并且对asp.net MVC3生成的内容是否有限制?

Am I expected to fill in the rest? Is this a usual behaviour and are there limit to what asp.net MVC3 could generate?

推荐答案

是的,这是标准行为.您可以检查默认的T4模板并查看其工作方式,该模板应位于C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML\Create.tt

Yes, this is standard behavior. You can examine the default T4 Template and see how it works, it should be located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML\Create.tt

最重要的方法是GetEligibleProperties-如您所见,它仅获取基本类型(公共类型等).

The most important method is GetEligibleProperties - as you can see it gets only primitive types (that are public and so on).

这是在ASP.NET MVC项目中处理HttpPostedFile的示例

Here's an example of dealing with HttpPostedFile in ASP.NET MVC projects Can EditorFor() be used to create <input type="file">?

这篇关于无法生成用于文件上传的支架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆