Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
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---

C#
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.
Posted

1 solution

You did not explain how your question formulated in the title related to the rest of the question. The piece of code throwing the exception is related to reading some data as base64 (which could be done using this method: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx[^], or something similar). And you did not show this piece of code. However, most likely, your input data is not base64 data. Locate this piece of code and check up.

Besides, catch the exception under debugger and look at the Debug Windows "Call stack". It will show you where the call came from.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900