I have to add a image to my database My Database is as follows
TableName = Product
- PId[int]
- PImage[nvarchar(max)]
I am making an application in ASP.NET MVC using DB FIRST APPROACH so my model class is as follows (which is auto generated)
using System;
using System.Collections.Generic;
public partial class Product
{
public int PId { get; set; }
public string PImage { get; set; }
}
My Controller for adding a new image is as follows. I am doing this way because my view is in React
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(string myData)
{
var details = Newtonsoft.Json.Linq.JObject.Parse(myData);
int PId = Convert.ToInt32((string)details["PId"]);
string PImage = [(string)details["PImage"]]; // An error is coming Cannot implicitly convert type 'System.Web.HttpPostedFileBase' to 'string'
Product p = new Product() { PId = PId, PImage = PImage };
db.Products.Add(p);
db.SaveChanges();
return View();
}
My view is fine It is returning both PId and PImage PId is being saved in db The problem is i don't know how to save images in db.