asp.net- mvc pass variables from one controller (action) to another controller (action)

家住魔仙堡 提交于 2019-12-13 05:43:47

问题


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");

Here is the full registration method

[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.


回答1:


Use tempData How to RedirectToAction in ASP.NET MVC without losing request data



来源:https://stackoverflow.com/questions/1164021/asp-net-mvc-pass-variables-from-one-controller-action-to-another-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!