0

I have ASP.NET Core 3.1 MVC app and such controller definition:

public class MainController : Controller
{
    private readonly ILogger<HomeController> _logger;
    private readonly IWeatherService _weatherService;

    public MainController(ILogger<HomeController> logger, IWeatherService weatherService)
    {
        _logger = logger;
        _weatherService = weatherService;
    }

    public IActionResult SelectCity()
    {
        return View();
    }

    [HttpPost]
    public async Task<IActionResult> ShowChart([FromForm] SettelmentModel settelment)
    {
        var lat = double.Parse(settelment.Lat, CultureInfo.InvariantCulture);
        var lon = double.Parse(settelment.Long, CultureInfo.InvariantCulture);
        var data = await _weatherService.GetHistoricalForecast(lat, lon);
      
        return View("ShowChart", data);
    }
}

The app processes the ShowChart method and finds the ShowChart view, but does not open it in the browser. And just stays on the same View from ShowChart method was requested.
I expected it would route to /Main/Chart and would open the Chart view. What I am doing wrong?

enter image description here

7
  • Do you actually have a <form> in the SelectCity view, or do you POST to ShowChart with ajax? Commented Aug 15, 2020 at 13:41
  • In which folder do you have the ShowChart.cshtml file? Commented Aug 15, 2020 at 13:42
  • @GSerg, yes, i have a form in SelectCity View, but i do POST with ajax. Commented Aug 15, 2020 at 13:45
  • This should have what you're looking for. Mirror the top answer. Commented Aug 15, 2020 at 13:45
  • 2
    If you post with ajax, then naturally it's your responsibility to receive the response in the javascript code and insert it into the appropriate part of the page. If you want to replace the entire page with the response, then it's much easier to not post with ajax and just let the browser do it. Commented Aug 15, 2020 at 13:47

0

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.