skip to Main Content
<form>
  <div>
    <input for="IPMaquina" type="text" placeholder="IP da Máquina">
    <button>Estado Máquina</button>
    <button type="button" onclick="window.location.href='JCash_SubPages/VNEconfig';" style="text-decoration: none; color: black;">Configuração</button>
  </div>

For some reason the onclick action won’t redirect to the VNEconfig View and leads to a 404 Error

If I move it to the same directory it works

however I don’t consider this a fix as there will be more Views and I’d like to organize it early on.

2

Answers


  1. Are you missing out the exact path of the file along with its extension?

    Perhaps you need to specify it as:

    onclick="window.location.href='JCash_SubPages/VNEconfig.cshtml';"
    
    Login or Signup to reply.
  2. ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions.

    The ASP.NET Core MVC template generates conventional routing code similar to the following:

    app.MapControllerRoute(
         name: "default",
         pattern: "{controller=Home}/{action=Index}/{id?}");
    

    The route template "{controller=Home}/{action=Index}/{id?}": Matches a URL path like /Products/Details/5
    Extracts the route values { controller = Products, action = Details, id = 5 } by tokenizing the path.

    The extraction of route values results in a match if the app has a controller named ProductsController and a Details action:

    public class ProductsController : Controller
    {
        public IActionResult Details(int id)
        {
            return ControllerContext.MyDisplayRouteInfo(id);
        }
    }
    

    Read Routing to controller actions in ASP.NET Core to know more.

    the onclick action won’t redirect to the VNEconfig View

    You can create an action in the Home controller , go to the VNEconfig action then to redirect JCash_SubPages/VNEconfig View:

    public IActionResult VNEconfig()
            {
                return View("JCash_SubPages/VNEconfig");
            }
    

    Modify your code like:

    <button type="button" onclick="window.location.href='/Home/VNEconfig';" style="text-decoration: none; color: black;">Configuração</button>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search