从一个控制器(动作)到另一个控制器asp.net- MVC传递变量(动作) [英] asp.net- mvc pass variables from one controller (action) to another controller (action)

查看:627
本文介绍了从一个控制器(动作)到另一个控制器asp.net- MVC传递变量(动作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有做的asp.net登录名和用户登记的AccountController。 (寄存器作用下。经过那就是成功的我也想把这个用户数据添加到心灵的另一个表称为用户。现在,我有一个UsersController,并呼吁创建所以你可以看到下面我有一个动作行:

i have an AccountController that does the asp.net login and user registration. (Register action below.. After that is successful i also want to add this user data to another table of mind called users. Right now i have a "UsersController" and an action called "Create" so as you can see below i have the line:

return RedirectToAction("Create", "Users");

下面是完整的注册方法

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Register(string userName, string email, string password, string confirmPassword, string address, string address2, string city, string state, string homePhone, string cellPhone, string company)
    {
        ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
        if (ValidateRegistration(userName, email, password, confirmPassword))
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus =        MembershipService.CreateUser(userName, password, email);

            if (createStatus == MembershipCreateStatus.Success)
            {
                FormsAuth.SignIn(userName, false /* createPersistentCookie */);
                return RedirectToAction("Create", "Users");
            }
            else
            {
                ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
            }
        }

        // If we got this far, something failed, redisplay form
        return View();
    }

我的问题是,我想所有的参数(用户名,电子邮件,地址等)传递到我的行动,因为这些都是在用户表中的字段,以及

my issue is that i want to pass all of the arguments (userName, email, address, etc) into my action as these are fields in the users table as well

我如何将参数传递给这个其他行动或者是有一些其他的推荐做法同时做多个动作,并保持变量的状态。

How do i pass arguments to this other action or is there some other recommended practices to do multiple actions at once and keep the state of the variables.

推荐答案

使用TempData的<一个href=\"http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data\">http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data

Use tempData http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data

这篇关于从一个控制器(动作)到另一个控制器asp.net- MVC传递变量(动作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆