Upload pic in model asp net core


ASP.NET is a popular programming language used for building web applications. In this article, we will explore how to upload a in a model using ASP.NET Core.

Step 1: Create a Model

The first step is to create a model that will represent the data of the picture. Let's create a model called “Picture” with the following :

public  Picture
    public int Id { get; set; }
    public string  { get; set; }
    public byte[] Data { get; set; }

In this example, we have an Id property to uniquely identify the picture, a FileName property to store the name of the uploaded file, and a Data property to store the binary data of the picture.

Step 2: Create a View

Next, we need to create a view to allow users to upload a picture. Let's create a view called “UploadPicture.cshtml” with the following code:

@model Picture

In this view, we have a form with an input field of type “file” to allow users to select a picture file. When the form is submitted, it will call the “Upload” action method in the controller.

Step 3: Create a Controller

Now, let's create a controller called “PictureController” with an action method called “Upload” to the picture upload. Here's the code for the controller:

In this controller, we have an action method called “Upload” that takes a Picture as a parameter. Inside the method, we check if a file has been selected and then read the file data into a byte array. We can then save the picture to the database or perform any necessary operations.


In this article, we have learned how to upload a picture in a model using ASP.NET Core. By following the steps outlined above, you can easily picture upload functionality in your ASP.NET Core web application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents