.net MVC4注册后跳转

akak01 2013-10-05 02:23:35
我想实现在http://localhost/Account/Register页面注册点击提交后,仍在当前URL下显示注册结果信息,是否可行?
就像小米的,在https://account.xiaomi.com/pass/register注册,点击注册后在当前URL下显示One last step, please activate your account

An activation mail has been sent to your email

Please check your email fdasfda@qq.com,click on the link in the email to activate your account
...全文
583 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanxuemaxavier 2013-10-11
  • 打赏
  • 举报
回复
using return RedirectToAction("ConfirmationPage","Account", new {message = "Your registration will need be confirmed"})
beyond_me21 2013-10-05
  • 打赏
  • 举报
回复
上面这中方式有一个不好的地方是用户提交数据后如果刷新当前页会导致数据重复提交 还有一种方式是你的form提交用ajax方式
beyond_me21 2013-10-05
  • 打赏
  • 举报
回复

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.Email, model.Password, new
                    {
                        UserName = model.UserName, 
                        Question = model.Question,
                        Answer   = model.Answer,
                        Telphone = model.Telphone 
                    });
                   // WebSecurity.Login(model.Email, model.Password);
                  //  return RedirectToAction("Index", "Home");
                     
                    return View("这里写你另一个视图名称,该视图显示注册成功后的内容",model);
                    
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
 
            // If we got this far, something failed, redisplay form
            return View(model);
        }
akak01 2013-10-05
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
当然可行。 直接跳转到当前页,设置TempData为注册成功的信息,并且在控制器中判断下。
感谢版主大大,受宠若惊。 呃,刚开始接触MVC,怎么设置TempData呢? 下面是controller的代码
      //
        // GET: /Account/Register

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


        //
        // POST: /Account/Register

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.Email, model.Password, new
                    {
                        UserName = model.UserName, 
                        Question = model.Question,
                        Answer   = model.Answer,
                        Telphone = model.Telphone 
                    });
                   // WebSecurity.Login(model.Email, model.Password);
                  //  return RedirectToAction("Index", "Home");
                    
                    return RedirectToAction("Registed", "Account");
                   
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
这要怎么设置呢?添加一个ActionResult ?
threenewbee 2013-10-05
  • 打赏
  • 举报
回复
当然可行。 直接跳转到当前页,设置TempData为注册成功的信息,并且在控制器中判断下。

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧