I'm new in ASP.Net MVC and I'm working with an image column in my database. My question is how to retrieve image path from controller and send to HttpPostedFileBase image model? I'm getting the error in my code telling me that in Image = row.Image
cannot implicitly convert type 'string' to 'system.web.httppostedfilebase'
Here's my code:
Controller
public ActionResult CategoryForm(int? Id, int CategoryGroupId)
{
if (Id != null)
{
model = (from row in db.Categories
where row.Id == Id
select new NewCategoryViewModel
{
Id = row.Id,
CategoryGroupId = CategoryGroupId,
Name = row.Name,
Description = row.Description,
Image = row.Image,
Status = row.Status,
isMain = row.isMain
}).Single();
}
return PartialView("_CategoryFormPartialView", model);
}
Model
public class NewCategoryViewModel
{
public int Id { get; set; }
public int CategoryGroupId { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
public HttpPostedFileBase Image { get; set; }
[Required]
public bool Status { get; set; }
[Required]
[Display (Name = "Display as main category?")]
public bool isMain { get; set; }
}
Thanks for helping me.