How to upload files using EditorTemplates? RRS feed

  • Question

  • Sir,

    I am developing an application in ASP.Net MVC Razor view where I have used EditorTemplates for one of my views to enable users to add family details. The view for Create is as below:

        ViewBag.Title = "Create";
    <h2>Create Pensioner</h2>
    @using (Html.BeginForm()) 
         <div class="row">
        <div class="col-md-6">
            <div class="col-md-6">
                 <button type="submit">Create</button>

    Rest of the views reside in the EditorTemplate folder.

    The problem is that in one of the views that belong to the EditorTemplates folder, I need to upload images. To upload images, HTML helper :

    @using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { enctype = "multipart/form-data" }))

    is to be used where Action and controller are predefined. In EditorTemplates, since there is no need of creating separate views for Create and  Edit, it does not allow to use the BeginForm for it is associated with a single action. Consequently, HttpPostedFileBase returns null value and file could not be uploaded.

    Please explain how to upload files in the scenario described above.



    • Edited by ArunKhatri Monday, August 28, 2017 4:27 PM
    • Moved by 宝宝徐 Wednesday, August 30, 2017 7:16 AM
    Monday, August 28, 2017 4:24 PM

All replies

  • Hi MickVet29,

    Thank you for posting in MSDN forum.

    This forum is discussing about the .Net Framework Setup and Servicing, from your description, as your issue is related to MVC and Test Web Server, I recommend you post a new thread to: https://forums.asp.net/1146.aspx/1?MVC for a much professional support.

    Thank you for your understanding.

    Best Regards,

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 29, 2017 5:30 AM