-1

I'm using ASP.Net MVC 5, and I want to pass data from the controller to the view WITHOUT adding it to the URL.

I've tried it like this:

public ActionResult Index(LoginViewModel loginViewModel)
{
    var landingPgVm = new LandingPgViewModel();

    landingPgVm.ElectionName = loginViewModel.ElectionName;
    landingPgVm.LandingPageTitle = loginViewModel.LandingPageTitle;
    landingPgVm.LandingPageMessage = loginViewModel.LandingPageMessage;

    return View("Landing", landingPgVm);
}

And this:

public ActionResult Index(LoginViewModel loginViewModel)
{
    var landingPgVm = new LandingPgViewModel();

    landingPgVm.ElectionName = loginViewModel.ElectionName;
    landingPgVm.LandingPageTitle = loginViewModel.LandingPageTitle;
    landingPgVm.LandingPageMessage = loginViewModel.LandingPageMessage;

    ViewData["lpvm"] = landingPgVm;

    return View("Landing");
}

And still, I get this:

http://localhost:nnnnn/Landing?VotingIsOpen=False&UserIp=%3A%3A1&BrowserAgent=Mozilla%2F5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F73.0.3683.103%20Safari%2F537.36&ElectionId=1&LoginId=********&LoginPin=*********&ElectionName=2019%20Member-at-Large%20Board%20Election&LandingPageTitle=Success%21&LandingPageMessage=Landing%20Page%20MESSAGE
Rufus L
  • 36,127
  • 5
  • 30
  • 43
Scott Fraley
  • 378
  • 4
  • 14
  • Have you tried passing your parameters in `[FromBody]`? – Jonathon Chase May 03 '19 at 22:44
  • 2
    I'm not clear on how you're getting from "passing data from the controller to the view" (something that happens entirely on the server) to something affecting the URL. When are you seeing the URL change? – nlawalker May 03 '19 at 22:44
  • @JonathonChase isn't that only for Retrieval of the data in a controller method? I've thought about putting the data into the body, but that would require a POST, which I'm not at all sure how to do (or if it's even possible) from `RedirectToAction()`. – Scott Fraley May 03 '19 at 22:49
  • @ScottFraley I'm assuming here that the url parameters are being passed from your login page, it's the LoginViewModel values that are getting plastered over your url with values such as `LoginId=********&LoginPin=*********` being included. They don't look like they would be part of your landing page view model. [Maybe you should stuff it in tempData instead](https://stackoverflow.com/questions/22505674/can-we-pass-model-as-a-parameter-in-redirecttoaction) – Jonathon Chase May 03 '19 at 22:52
  • @JonathonChase you were right, I was sending the wrong ViewModel to the wrong page. – Scott Fraley May 06 '19 at 15:27
  • Is it really necessary to down-vote me for making an honest mistake? :( – Scott Fraley Aug 28 '19 at 18:56

1 Answers1

0

So sorry that I let my frustration at, what turned out to be MYSELF, spill over onto these pages.

It's been some time since I've done a 'standard' MVC site and forgot how the logic is supposed to flow. (Sometimes it takes getting all the way to posting to SO before I finally figure out/realize the error(s) of my way(s)).

Thanks to info found on the MS docs site here (https://learn.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset), namely, the POST method example under the "You must also update the HttpPost Login action method:" text, I've got it figured out.

Scott Fraley
  • 378
  • 4
  • 14