Answer the question
In order to leave comments, you need to log in
How to upload image to MS SQL database?
I am developing a website in Asp.Net Core. There is a field in the database with type image. You need to fill in the data through the Create page (including adding an image), and then display it on another page. When adding an image to the database, the corresponding image field value for this row is Null. How to solve this problem? To upload an image I tried:
<input asp-for="Img" class="form-control" type="file" />
------------------------------------------------------------------
<input type="file" id="file" class="custom-file-input" name="Img">
Answer the question
In order to leave comments, you need to log in
Most likely in the tag
<form enctype="multipart/form-data" ... > ... </form>
must be put. Between the markup and the base there is an abyss of a very different secret code, which, judging by the question, you propose to guess. What is the problem?
Did you check the code under debugging?
Does the file come in the request handler?
Does it go through all layers of business logic?
What method is trying to save the file to the database? Through a stored procedure call or direct Insert or a call through some ORM layer?
Why don't you use db data type - byte array?
If the answer to the first question is no, then most likely the correct answer was given by cicatrix
@{
ViewBag.Title = "Upload";
}
<h3>Выберите файл для загрузки</h3>
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new {enctype="multipart/form-data"}))
{
<input type="file" name="upload" /><br>
<input type="submit" value="Загрузить" />
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question