-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.

1
  • 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. Commented Dec 22, 2020 at 17:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.