I have a Login form, It asks for UserName, Password, TokenID (Each user knows his token, they get it to access an API). I would like to be able to Obtain that Token API that they entered and Pass it on to /Home/Index. What is the best way to go about doing that?
Asked
Active
Viewed 969 times
0
-
Is it only from one `Login` to `Home`? Or you may need it even after that? – Mohayemin Aug 26 '12 at 16:02
1 Answers
1
Ok, first you have a View where user will be entering UserName
, Password
and TokenId
so let the view have a model like the one shown below.
public class LoginModel{
public string UserName{get; set;}
public string Password{get; set;}
public string TokenId{get; set;}
}
and from the view you can return this model, which will hold all these values.
Now as you need to pass these values to Home/Index
you can have your form submitted to the Index
action.
public ActionResult Index(LoginModel model)
{
string gotcha = model.TokenId;
}
But incase if you want to submit a form to a different action of say a controller 'Login' and then pass this values to a different controller, you can do something like this.
// defined in Login Controller
public ActionResult Index(LoginModel model)
{
TempData["TokenId"] = model.TokenId;
return RedirectToAction("Dashboard","Account");
}
// defined in Account Controller
public ActionResult Dashboard()
{
string gotVal = TempData["TokenId"]
}
there are more ways to pass values between two action, see this link

Community
- 1
- 1

Yasser Shaikh
- 46,934
- 46
- 204
- 281