コード例 #1
0
        public ActionResult AddStudent(StudentTable123 model) //the "model" is used for receive the data from view(UI)
        {
            StudentTable123 std = new StudentTable123();      //this object is used for receive the data from model

            if (ModelState.IsValid)
            {
                std.Id          = model.Id;
                std.Fname       = model.Fname;//Its stores the data with respective fields
                std.Lname       = model.Lname;
                std.Email       = model.Email;
                std.Mobile      = model.Mobile;
                std.Description = model.Description;

                if (model.Id == 0)
                {
                    obj1.StudentTable123.Add(std);
                    obj1.SaveChanges();
                }
                else
                {
                    obj1.Entry(std).State = EntityState.Modified;
                    obj1.SaveChanges();
                }
            }
            ModelState.Clear();

            return(View("Student"));
        }
コード例 #2
0
        public ActionResult FileUpload(HttpPostedFileBase file)
        {
            if (file != null)
            {
                Student1Entities db = new Student1Entities();
                //string ImageName = System.IO.Path.GetFileName(file.FileName); // fILE er name passo
                //// ekhane arekta line hobe j file copy korte hbe

                //string physicalPath = Server.MapPath("~/Image/" + ImageName);
                //// jodi ekhan theke path nite chao then image ei folder e copy kore age rakho

                int          fileSizeInBytes = file.ContentLength;
                MemoryStream target          = new MemoryStream();
                file.InputStream.CopyTo(target);
                byte[]     data    = target.ToArray();
                tblStudent student = new tblStudent();
                student.FirstName = Request.Form["firstname"];
                student.LastName  = Request.Form["lastname"];
                student.imagefile = data;
                db.tblStudents.Add(student);
                db.SaveChanges();
            }
            return(RedirectToAction("../home/DisplayImage"));
        }