Thursday, June 28, 2018

Razor Pages and Json help

Hi! I created a simple project where a user fills a form and when she submits it, there is a logic that creates a URL that access an external API and obtains a list of items, that could go from 0 to over 250 items. That result is sent in JSON and I deserialize it to show in a different page. I am able to do that easily using ASP Net Core MVC.

Now, I am trying to update this project to learn Razor Pages, and it's not working.

That's the code I use in my MVC's controller:

[HttpPost] public async Task<ActionResult> Resultado(string urlJson, int ? precoMax) { HttpClient httpClient = new HttpClient(); var resultado = await httpClient.GetStringAsync(urlJson); Produto.Rootobject produtos = JsonConvert.DeserializeObject<Produto.Rootobject>(resultado); return View(produtos); } 

This is sort of what I think it should be in Razor Pages:

 public async Task<IActionResult> OnPostAsync(string urljson) { var httpClient = new HttpClient(); var resultado = await httpClient.GetStringAsync(urljson); Produto.Rootobject Produtos = JsonConvert.DeserializeObject<Produto.Rootobject>(resultado); return RedirectToPage("ListaSugestoes", Produtos); } 

It doesn't work, or, I am doing something wrong. Any help would be greatly appreciated.

If the conclusion is that Razor Pages is not ready for my project, fine, I can live with that!!

Razor Pages and Json help Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team