-1

I am trying to upload file and storing into the database.

Here is my model class:

 public string screen_print_one { get; set; }

This is my view markup:

<div class="form-group">
    <label asp-for="screen_print_one" class="control-label"></label>
    <input type="file" asp-for="screen_print_one" class="control-label" name="file" id="file" />
</div> 

I am not able to see value (or path) in my controller for the screen_print_one.

Please help me with the controller code that how I can upload file on server and store path inside the database.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I'd look into the ````FileUpload```` class. If you Google 'ASP FileUpload MVC' you'll get some good starting guides. Once you start coding yourself and have any further issues, I'd then post whatever code you have, along with any error messages, and then we can help further. – JohnPete22 Dec 22 '20 at 17:20

1 Answers1

0

If you want to upload a File to server. Your model type must be HttpPostedFileBase instade of string. So you can save your file a path on your server and save the file path in your db. Also you must add enctype = "multipart/form-data" attribute to your form tag to upload file. Don't forget to give write permission to the folder which you upload the file on your server.

Cagri D. Kaynar
  • 348
  • 1
  • 10