MVC Login Page using SQL Database and Razorīinding Angular JS Bind HTML table from SQL in ASP.NET MVC C#īind|Populate ASP.NET MVC C# Dropdownlist from SQLĬreating a Login Page in ASP.NET MVC C# using SQL table and RazorĬreating a Registration page in ASP. Hope you found this post useful.ĪSP.NET MVC Add and Retrieve Cookies Example. In order to support file upload, make sure to declare the attribute enctype 'multipart / form data' on the form tag, otherwise you will find ASP.NET No files can be read in the Controller of core MVC. If you liked this post and found it useful, please like our Facebook page and share this with your friends and other people. (Server.MapPath("~")+finalPath) Ĭon = new SqlConnection(connectionString) Ĭmd.CommandType = Therefore, the controller action that is tasked to process the uploaded files needs a parameter that represents a collection of HttpPostedFileBase objects. Static String connectionString = Source=192.168.100.39 Initial Catalog=MVCSample User ID=sa Password=789 Integrated Security=True " Files are uploaded to the server in the Request.Files collection, each one of which is mapped to an HttpPostedFileBase object by the default MVC model binder. Public class ProductsController : Controller Now edit the Controller to save the file as well as the data in our database:Ĭontrollers>ProductsController.cs: using MVCSample.Models
Insert into tblProducts (ProductName, ProductDesc, ProductImage) values * from tblProducts ProductId int not null identity(1,1) primary key,Ĭreate procedure nvarchar(50), nvarchar(50), nvarchar(100) (Server.MapPath("~")+finalPath) //Using this codeīelow is my database script: Create database MVCSample String finalPath = "\\UploadedFile\\" +strDateTime + When the Model Obj with filepath hits our Controller method, it will get saved: