© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
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
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);
        }
        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>
@{
   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>
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ View not found?
C#CC# / help
2y ago
❔ Locals view not found
C#CC# / help
3y ago
Edit view directs to 404 not found
C#CC# / help
14mo ago
❔ View cannot be found.
C#CC# / help
4y ago