public ActionResult CreateVacancy(VacancyVM model, HttpPostedFileBase postedFile1, FormCollection form) { IStructuredetailRepository repo = new StructuredetailRepository(); var city = new SelectList(new[] { new { ID = "1", Name = "Karachi" }, new { ID = "2", Name = "Lahore" }, new { ID = "3", Name = "Islamabad" } }, "Name", "Name", "1" ); ViewBag.getcitylist = city; var deplist = repo.Getdep().ToList(); SelectList list = new SelectList(deplist, "DepartmentId", "DepartmentName"); ViewBag.getdep1list = list; var levellist = new SelectList(new[] { new { ID = "1", Name = "1" }, new { ID = "2", Name = "2" }, new { ID = "3", Name = "3" }, new { ID = "4", Name = "4" }, new { ID = "5", Name = "5" } }, "Name", "Name", "1" ); ViewBag.getlevellist = levellist; if (postedFile1 == null) { ModelState.AddModelError("CustomError", "Please select Test"); } else if (!(postedFile1.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || postedFile1.ContentType == "application/pdf")) { ModelState.AddModelError("CustomError", "Only .docx and .pdf file allowed"); return(View()); } else if (postedFile1 != null) { string fileName1 = Guid.NewGuid() + Path.GetExtension(postedFile1.FileName); postedFile1.SaveAs(Path.Combine(Server.MapPath("~/TestPaper"), fileName1)); var AddVacant = repo.Addvac(model.VacancyName, model.CityName, model.PositionId, model.DepartmentId, model.RequiredQualification, model.JobLevel, model.MarksCriteria, fileName1); repo.Addvacant(AddVacant); repo.Save(); TempData["SuccessMessage11"] = "Vacancy Created"; } return(View()); }