Show / Hide Table of Contents

    File Upload Fields

    If you need to collect uploaded file data then you can use ASP.NET Core MVC's IFormFile type for your model property, e.g.:

    public IFormFile FileUpload { get; set; }
    

    In order for file uploads to work you will need to set the encoding type on the form to multipart/form-data (as opposed to the default), e.g.:

    • Tag Helpers variant
    • HTML Helpers variant
    <chameleon-form enctype="Multipart">
        @* ... *@
    </chameleon-form>
    
    @using (var f = Html.BeginChameleonForm(encType: EncType.Multipart)) {
        @* ... *@
    }
    

    To then use the file upload in your controller action you use the documented approaches to handle the uploaded file(s). If you want the field to be Required you can annotate with [Required].

    ChameleonForms doesn't currently support generating the correct HTML to handle multiple file uploads, but feel free to submit an issue or pull request to discuss adding that feature.

    Default HTML

    When using the Default Field Generator then the default HTML of the Field Element will be:

    <input %validationAttrs% %htmlAttributes% id="%propertyName%" name="%propertyName%" type="file" value="%value%" />
    

    If the field is marked as [Required] then required="required" will be added.

    • Improve this Doc
    Back to top © Copyright 2012-2020 MRCollective, Rob Moore, Matt Davies and the contributors to ChameleonForms.