May 06, 2014 by Anuraj
.Net .Net 4.0 ASP.Net MVC
This post is about upload file to server using ASP.Net MVC 4. First you need to modify the controller to accept the posted file along with the model. So you can modify it like this.
And in View, you need to include htmlAttribute to upload files.
Make sure the parameter name in the action method and File upload control id is same, otherwise it may not work.
Instead on including the HttpPostedFileBase parameter in the action method, you can also use Request.Files collection. Here is the implementation using Request.Files.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub