I click a button in my webapp and the page goes to the url "https://localhost:44321/Home/Generate". When I click the button a second time the page goes to the url "https://localhost:44321/Home/Home/Generate" and I get an error because the page is not found.
I have a button with the following code:
<form method="post" action="Home/Generate">
<input type="submit" value="Generate" />
</form>
I have a Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvcWithDefaultRoute();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
}
and I also tried to add:
routes.MapRoute(
name: "generate",
template: "{controller=Home}/{action=Generate}");
In my HomeController I call the method after a click like this:
[HttpPost]
public IActionResult Generate()
{
bool result = false;
if (result) return RedirectToAction("Window", new { param = order.ID.ToString() });
else return RedirectToAction("Window", 0);
}
public IActionResult Window(string param)
{
if (param == "NotReady")
{
ViewBag.JavaScriptFunction = string.Format("ShowNotReady();");
}
else
{
ViewBag.JavaScriptFunction = string.Format("ShowError();");
}
return View("Index");
}
public IActionResult Index()
{
return View();
}
What I have to do, that "https://localhost:44321/Home/Generate" is the url after every button click, not only after the first click?