0

In Asp.Net MVC, the Account controller's Login method, if successful, returns RedirectToLocal(returnUrl);

I want to add a string to return. I thought ViewBag or TempData would do, but the View finds those to be empty. So I guess those don't get passed to the View, even though that's their exact purpose, from what I read.

There's got to be an easy way...other than returning to Classic ASP.

1
  • Please clarify what you're trying to do. For example, what would you do in ASP 3.0? What "data" would you "send"? How would you "read" it? How is it used? Commented Dec 20, 2018 at 16:50

1 Answer 1

1

It sounds like you want to declare (optional?) parameters on the route you're redirecting to.

For example, something like:

 return RedirectToAction("Action", new { id = 99 });

Here are a few links that might help:

MVC RedirectToAction passing route parameters

Passing data from one controller to another in ASP.NET MVC

PS:

Please don't return to "Classic ASP.Net" (or "even-more-classic ASP 3.0" ;)). Get familiar with MVC, and look forward to ASP.Net Core (which is MVC from the ground up ;))

Sign up to request clarification or add additional context in comments.

3 Comments

Did I say I wanted to pass data from one controller to another? No. I said from a controller to a view. It comes down to my not understanding how Asp.Net assembles the html returned to the browser. The controller action might return any of these: View(), View("someViewName"), RedirectToLocal(returnUrl), RedirectToAction(view, params), View(model), etc.I want to be able to grab some data that is present in the controller action but is not in the model and then pass it to the View of my choice.
Yes, an XY problem. What I wanted to do was display a user's real name, not his e-mail address/login, after he had logged in. (Lots of griping deleted to save space.) Solution: add "@using System.Security.Claims" to the top of _LoginPartial.cshtml, and replace "User.Identity.GetUserName()" with "@(((ClaimsIdentity)User.Identity).FindFirstValue("FullName"))". Of course, FullName was added as a field in AspNetUsers, and this was added in IdentityModel.cs: "userIdentity.AddClaim(new Claim("FullName", $"{FullName}"));" This is found code; I can't explain why it works. What's a claim anyway?
Glad you found what you needed! "Claim" is InfoSec jargon; it's a kind of "attribute". You can read more about it here: learn.microsoft.com/en-us/aspnet/core/security/authorization/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.