首页 > 解决方案 > ASP.NET MVC 按钮不触发导航

问题描述

我正在学习新的 ASP.NET MVC。我正在尝试在屏幕之间设置导航,如下所示

家庭控制器.cs

public class HomeController : Controller
{       
    public ActionResult Welcome(string newId)
    {
        ViewBag.Message = "Welcome to my shop.";
        return View();
    }
}

欢迎.cshtml

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{
    <h1>The shoppee</h1>    
    <input type="button" title="Cart" value="Shop Items" onclick="window.location.href='@Url.Action("SelectItems", "Cart") %>'" />
}

我用 SelectItems.cshtml 构建了一个新的 CartController。我已将它们添加到 routeconfig.cs。但是上面的按钮根本没有触发。我可以使用手动导航到 url

http://localhost:portnumber/Cart/SelectItems

标签: c#asp.net-mvcrazornavigation

解决方案


推荐阅读