コード例 #1
0
        //public async Task<IActionResult> Create([Bind("ID,Name,Content,Price,CreatedAt,UpdatedAt")] Project project)
        public async Task <IActionResult> Create([Bind("ID,Name,Content,Price,Image")] ProjectCreate projectCreate)
        {
            Project projectModel = null;

            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(projectCreate);
                string fileLocation   = HttpContext.Request.Scheme + "://" + this.Request.Host + "/images/" + uniqueFileName;

                projectModel = new Project
                {
                    Name    = projectCreate.Name,
                    Content = projectCreate.Content,
                    Price   = projectCreate.Price,
                    //Picture = uniqueFileName,
                    Picture = fileLocation,
                };

                _context.Add(projectModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(projectModel));
        }
コード例 #2
0
        //public async Task<IActionResult> Create([Bind("ID,Title,Note,Video,Header,Tag,ProjectId,CreatedAt,UpdatedAt")] Education.Models.Task task)
        public async Task <IActionResult> Create([Bind("ID,Title,Note,Video,Header,Tag,ProjectId")] Education.Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.Project, "ID", "ID", task.ProjectId);
            return(View(task));
        }