//此处绑定的ID不可省略
        public async Task <IActionResult> Edit(int id, [Bind("ID,title,author,source,fb_time,wz_content,wz_style,state,userID")] Science_essayViewModel science_essayViewModel)
        {
            if (id != science_essayViewModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(science_essayViewModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Science_essayViewModelExists(science_essayViewModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction("Details",new { id=id });
                return(Content("<meta http-equiv='Content-Type' content='text/html; charset = UTF-8' /><script>alert('成功修改文章!');location.href='/PersonCenter/Details/" + id + "'</script>", "text/html"));
            }
            return(View(science_essayViewModel));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,comment,comment_time,userID,essayID")] Forum_msgViewModel forum_msgViewModel)
        {
            if (id != forum_msgViewModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(forum_msgViewModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Forum_msgViewModelExists(forum_msgViewModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["essayID"] = new SelectList(_context.Science_essay, "ID", "ID", forum_msgViewModel.essayID);
            //ViewData["userID"] = new SelectList(_context.users, "ID", "password", forum_msgViewModel.userID);
            ViewData["userID"] = new SelectList(_context.users, "ID", "userID", forum_msgViewModel.userID);
            return(View(forum_msgViewModel));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,title,author,source,fb_time,wz_content,wz_style,state,userID")] Science_essayViewModel science_essayViewModel)
        {
            if (id != science_essayViewModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(science_essayViewModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Science_essayViewModelExists(science_essayViewModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["userID"]   = new SelectList(_context.users, "ID", "username", science_essayViewModel.userID);
            ViewData["wz_style"] = new SelectList(_context.Science_essay, "ID", "wz_style", science_essayViewModel.wz_style);
            return(View(science_essayViewModel));
        }