这是我的代码,我想检查文件是否为具有任何扩展名的图像
[HttpPost]
public ActionResult Add(ServicesVM obj, HttpPostedFileBase file)
{
if (ModelState.IsValid || file != null)
{
if (file != null && file.ContentLength > 0)
{
Services newobj = new Services();
file = HttpContext.Request.Files[0];
file.SaveAs(Server.MapPath("/Uploads/" + file.FileName));
newobj.Image = "/Uploads/" + file.FileName;
newobj.Name = obj.Name;
newobj.Description = obj.Description;
obj_dal.AddService(newobj);
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Add");
}
}
else
{
return RedirectToAction("Add");
}
}