Am new to MVC, I was following a tutorial and got this error
I followed the every steps in the tutorial, but still getting the same error Here is the code for my view
@model _234CrudDemo.Models.ComplaintTicket
<div class="form-horizontal">
<h4>ComplaintTicket</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Message, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Attachment, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="ImageFile" required />
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Ministry, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Ministry, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Ministry, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
And here is my controller
public class ComplaintTicketController : Controller
{
//CRUDDataComplaintsEntities db = new CRUDDataComplaintsEntities();
//// GET: ComplaintTicket
//public ActionResult Index()
//{
// //var tickets = db.ComplaintsTickets.ToList();
// var tickets = (from x in db.ComplaintTicket
// join a in db.mins on x.Ministry equals a.Id
// select new TicketsIndexLists() { Id = x.Id, Title = x.Title, Message = x.Message, Attachment = x.Attachment, Name = a.Name }).ToList();
// return View(tickets);
//}
[HttpGet]
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(ComplaintTicket imageModel)
{
string fileName = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
string extension = Path.GetExtension(imageModel.ImageFile.FileName);
fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
imageModel.Attachment = "~/Image/" + fileName;
fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
imageModel.ImageFile.SaveAs(fileName);
//db.ComplaintTicket.Add(imageModel);
//db.SaveChanges();
//ModelState.Clear();
return View();
}
}
Here is my model class
public partial class ComplaintTicket
{
public int Id { get; set; }
public string Title { get; set; }
public string Message { get; set; }
[DisplayName("Upload Image")]
public string Attachment { get; set; }
public Nullable<int> Ministry { get; set; }
public virtual mins mins { get; set; }
public HttpPostedFile ImageFile { get; set; }
}
Please how do I resolve this, I have search for solutions here and try answers given to previous similar questions, but none worked for, its still giving me the same error, help needed. Am new to c# Thanks