public ActionResult AddCourse(Course c, CrsRelation cr, HttpPostedFileBase file) { var path = ""; string ImageName = ""; //for checking uploaded if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png" || Path.GetExtension(file.FileName).ToLower() == ".gif" || Path.GetExtension(file.FileName).ToLower() == ".jpeg") { ImageName = file.FileName; path = Path.Combine(Server.MapPath("~/Images/"), file.FileName); file.SaveAs(path); ViewBag.UploadSuccess = true; } cr.cid = c.cid; CourseBL.InsertToCrs(c, ImageName); CourseBL.InsertToCrsRelation(cr); Session["CourseID"] = c.cid; return(RedirectToAction("AddCourse")); }