C#C
C#4y ago
surwren

❔ The view 'GetModel1' was not found

An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'GetModel1' was not found. The following locations were searched:
/Views/Home/GetModel1.cshtml
/Views/Shared/GetModel1.cshtml


Why is this happening?

I'm trying to call an async method (GetModel1) to access an api endpoint, which should then return the desired value to the view.

Code is as follows:

HomeController.cs:
        public IActionResult Index(string result)
        {
            TempData["Output"]=result;
            return View();

        }


        [HttpGet]
        public async Task<IActionResult> GetModel1(int x, int y, int z)
        {
            //need basic verification for non-integers

            var httpClient = new HttpClient();

            var url = $"http://localhost:8080/model1?x={x}&y={y}&z={z}";
            var response= await httpClient.GetAsync(url);
            var result= await response.Content.ReadAsStringAsync();
            return Index(result);
        }


Code for razor view:

@{
   string output= (string)TempData["Output"];
}
  <form method="GET" action="Home\GetModel1">

        <label for="x">Repayment status in September:</label><br>
        <input type="text" id="x" name="x" value="-1"><br>

        <label for="y">Repayment status in August:</label><br>
        <input type="text" id="y" name="y" value="-1"><br>

        <label for="z">Repayment status in July:</label><br>
        <input type="text" id="z" name="z" value="-1"><br><br>

        <input type="submit" value="Submit">
    </form>

<div class="text-center" id="Model1">@output</div>
Was this page helpful?