Advertisement
cortez

CreateAction

Jun 9th, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. [HttpPost]
  2.         [ValidateAntiForgeryToken]
  3.         public ActionResult Create([Bind(Include="Name,CoachID,DivisionID,Established,Wins,Draw,Loss,GoalsScored,GoalsConceived")] Club club, HttpPostedFileBase logo)
  4.         {
  5.             if (ModelState.IsValid)
  6.             {
  7.                 int imageLength = logo.ContentLength;
  8.                 byte[] imageBytes = new byte[imageLength];
  9.                 logo.InputStream.Read(imageBytes, 0, imageLength);
  10.  
  11.                 club.Logo = imageBytes;
  12.  
  13.                 db.Clubs.Add(club);
  14.                 db.SaveChanges();
  15.                 return RedirectToAction("Index");
  16.             }
  17.  
  18.             ViewBag.CoachID = new SelectList(db.Coaches, "CoachID", "Name", club.CoachID);
  19.             ViewBag.DivisionID = new SelectList(db.Divisions, "DivisionID", "Name", club.DivisionID);
  20.             return View(club);
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement