public ActionResult Create([Bind(Include = "PostId,UserId,Title,Description,Image,Status,CategoryPostId")] Post post) { if (post.myfile != null && post.myfile.ContentLength > 0) { string imgName = Path.GetFileName(post.myfile.FileName); string imgExt = Path.GetExtension(imgName); if (imgExt.Equals(".jpg") || imgExt.Equals(".jpeg") || imgExt.Equals(".png")) { string imgPath = Path.Combine(Server.MapPath("~/Assets/img"), imgName); post.myfile.SaveAs(imgPath); post.Image = "/Assets/img/" + imgName; } else { ModelState.AddModelError("", "Wrong file type"); } } if (ModelState.IsValid) { post.UserId = User.Identity.GetUserId(); _postRepository.Add(post); return(RedirectToAction("Index")); } ViewBag.CategoryPostId = new SelectList(_categoryPostRepository.GetAll(), "CategoryPostId", "CategoryName", post.CategoryPostId); return(View(post)); }
// GET: Identity/Posts/Create public ActionResult Create() { var x = new SelectList(_categoryPostRepository.GetAll(), "CategoryPostId", "CategoryName"); ViewBag.CategoryPostId = new SelectList(_categoryPostRepository.GetAll(), "CategoryPostId", "CategoryName"); return(View()); }