如何在第一次部分视图中插入成功后加载第二次部分视图?

时间:2016-09-17 09:10:59

标签: asp.net-mvc partial-views

我有一个名为Register.cshtml的视图和名为_AddUser.cshtml_UserList.cshtml的2个部分视图。

当我运行项目时,会在视图中显示register.cshtml_AddUser.cshtml。我希望在成功插入_UserList partialview后加载_AddUser partialview

DefaultController:

 public class DefaultController : Controller
{
    UserRepository UR = new UserRepository();
    Automation_DBEntities database = new Automation_DBEntities();

    [HttpGet]
    public ActionResult Register()
    {
        return View();
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Register(Users user, HttpPostedFileBase file)
    {
        UserRepository blUser = new UserRepository();
        if (ModelState.IsValid)
        {
            ///////////////////SaveImage
            if (file != null)
            {
                if (user.UserImage != "no-photo.jpg")
                {
                    if (System.IO.File.Exists(Server.MapPath("/image/UserImage/" + user.UserImage)))
                        System.IO.File.Delete(Server.MapPath("/image/UserImage/" + user.UserImage));
                }
                user.UserImage = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                file.SaveAs(Server.MapPath("/image/UserImage/" + user.UserImage));
            }
            user.RegisterDate = DateTime.Now;
            if (blUser.Add(user))
            {
                return PartialView("_UserList");//Inserted
            }
            else
            {

            }
        }
        else
        {

        }
    }

    [HttpGet]
    public ActionResult AddUser()
    {
        return PartialView("~/Areas/Admin/Views/Shared/_AddUser.cshtml");
    }

    [HttpGet]
    public ActionResult UserList()
    {
        IQueryable<AutomationSystem.Models.DomainModel.Users> list = UR.Select();
        return PartialView("~/Areas/Admin/Views/Shared/_UserList.cshtml", list);
    }

0 个答案:

没有答案