Couldn't generate scaffold for file upload

≯℡__Kan透↙ 提交于 2020-01-05 07:25:50

问题


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

View Model

namespace myapps.Models.ViewModels
{
    public class UserPhotoUploadViewModel
    {

        public HttpPostedFile PhotoFile
        {
            get;
            set;
        }

        public Guid UserID
        {
            get;
            set;
        }
    }
}

Generated View

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

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


回答1:


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

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

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



来源:https://stackoverflow.com/questions/12686758/couldnt-generate-scaffold-for-file-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!