C
C#3y 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
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>
6 Replies
surwren
surwrenOP3y ago
Am I calling the
public async Task<IActionResult> GetModel1
public async Task<IActionResult> GetModel1
wrongly somehow?
ronkpunk
ronkpunk3y ago
have you tried to reverse slash in form action? from "Home\GetModel1" to "Home/GetModel1" another thing should be the route of your action in HomeController you can specify it like this [Route("home")] public class HomeController ... { [...] [HttpGet] [Route("mysuperroute") public async Task<IActionResult> GetModel1(int x, int y, int z) { } } and change form action to "home/mysuperroute" (maybe the last thing is better for WebAPI but I think it should work also in web pages) (if you specify Controller route you may also have to change url that pointing home controller)
surwren
surwrenOP3y ago
It's not working
ronkpunk
ronkpunk3y ago
none of them or just reverse slash?
surwren
surwrenOP3y ago
Nvm i fixed it Needed to redirecttoaction
Accord
Accord3y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server