调用控制器和操作方法并传递模型值 [英] call controller and action method and pass model values

查看:73
本文介绍了调用控制器和操作方法并传递模型值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里调用另一个控制器和操作方法

I'm calling another controller and action method here

    [HttpPost]
    public ActionResult Index(LoginModel loginModel)
    {
        if (ModelState.IsValid)
        { some lines of code . bla bla bla
          return RedirectToAction("indexaction","premiumcontroller");
        }
    }

现在,发生的事情是现在执行了premiumcontroller的indexaction.

Now, what happens is the indexaction of premiumcontroller is now executed.

如何将loginmodel(或loginmodel对象)的值传递给premiumcontroller?我想不通.谢谢.

How can i pass the values of loginmodel (or the loginmodel object) to the premiumcontroller? i cant figure it out. Thanks.

我正在使用asp.net mvc 3.

I'm using asp.net mvc 3.

推荐答案

您可以使用new关键字在控制器操作中传递值...

you can use new keyword to pass the values in the controller action...

return RedirectToAction(
    "indexaction",
    "premium", 
    new {
        Id = loginModel.Id,
        UserName = loginModel.UserName,
        Password = loginModel.Password   
    }
);

在您的其他控制器中

public ActionResult indexaction(int id, string uName, string paswrd)
{
    // do some logic...
}

这篇关于调用控制器和操作方法并传递模型值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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