Below is my View Code---
model IkkosAdminPortalWebSite.Models.RecordDetails
@{
ViewBag.Title = "Add";
Layout = "~/Views/Shared/_Layout.cshtml";
}
Add
@using (Html.BeginForm("Add", "RecordDetails", FormMethod.Post, new { enctype = "multipart/form-data", @data_ajax = "false" })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
RecordDetails
@Html.LabelFor(model => model.Actor)
@Html.EditorFor(model => model.Actor)
@Html.ValidationMessageFor(model => model.Actor)
@Html.LabelFor(model => model.Owner)
@Html.EditorFor(model => model.Owner)
@Html.ValidationMessageFor(model => model.Owner)
@Html.LabelFor(model => model.Category)
@Html.EditorFor(model => model.Category)
@Html.ValidationMessageFor(model => model.Category)
@Html.LabelFor(model => model.SubCategory)
@Html.EditorFor(model => model.SubCategory)
@Html.ValidationMessageFor(model => model.SubCategory)
@Html.LabelFor(model => model.Movement)
@Html.EditorFor(model => model.Movement)
@Html.ValidationMessageFor(model => model.Movement)
@Html.LabelFor(model => model.Thumbnail)
@* <label for="Thumbnail">Thumbnail</label> *@
<input type="file" name="Thumbnail" id="Thumbnail" />
@Html.ValidationMessageFor(model => model.Thumbnail)
@Html.LabelFor(model => model.IAPProductId)
@Html.EditorFor(model => model.IAPProductId)
@Html.ValidationMessageFor(model => model.IAPProductId)
<input type="submit" value="Create" />
}
*******
Model Class is---
public class RecordDetails
{
public string Actor { get; set; }
public string Owner { get; set; }
public string Category { get; set; }
public string SubCategory { get; set; }
public string Movement { get; set; }
public HttpPostedFileBase Thumbnail { get; set; }
public string IAPProductId { get; set; }
}
********
In Controller ActionResult code:
[HttpPost]
public ActionResult Add(RecordDetail record, HttpPostedFileBase Thumbnail)
// public ActionResult Add(RecordDetail record)
{
if (ModelState.IsValid)
{
RecordDetail objrec = new RecordDetail();
if (Thumbnail != null && Thumbnail.ContentLength > 0)
{
var filename = Path.GetFileName(Thumbnail.FileName);
objrec.Thumbnail = System.Text.Encoding.UTF8.GetBytes(filename);
}
objList.RecordDetails.Add(record);
objList.SaveChanges();
return RedirectToAction("RecordDetails");
}
return View(record);
}
*****************
DataBase ---Thumbnail Column DataType is Image.