HomeController 中路由设置中路由的 HTTP 404

HTTP 404 on Route in Route Setup in HomeController

我在家庭控制器中正确设置路由时遇到问题。 我正在尝试为我的电子邮件设置路由输入字段。这是我的 cshtml 代码片段:

<form method="post" action="/home/emailsignup">
            <input type="text" class="form-control" name="email" placeholder="you@example.com">
            <span class="input-group-btn btnstateless">
                <input type="submit" id="mailSignup"value="SUBSCRIBE"/>
            </span>
        </div>
    </form>

我正在尝试在 HomeController.cs 中设置操作路线 这是我的代码的一部分:

[Route("home/emailsignup")]
        [HttpGet]
        public ActionResult EmailSignupGet()
        {
                var cVM = new ConfirmedViewModel
                {
                    confirmationTitle = "Thanks!",
                    message = "",
                    nextStep = "<a href=\"/\">Return home</a>"
                };
                return View("Confirmed", cVM);

        }
        [HttpPost]
        public ActionResult EmailSignup(string email)
        {

            if (UtilsClass.IsValidEmail(email))
            {
Email.GreenArrowHelper.AddOrUpdateUserByEmailFetchAllInfo(email).ConfigureAwait(false);
                var cVM = new ConfirmedViewModel();
                cVM.confirmationTitle = "Thanks!";
                cVM.message = "";
                cVM.nextStep = "<a href=\"/\">Return home</a>";
                return View("Confirmed", cVM);
            }
            else
            {
                ErrorViewModel eVM = new ErrorViewModel
                {
                    title = "Hmm, something's not right.",
                    message = "That doesn't look like a valid email address. Please try again.",
                    nextstep = "<a href=\"/\">Return home</a>"
                };
                return View("Error", eVM);
            }


        }

我正在尝试 return 我的消息,但我在点击订阅时收到 HTTP 404 button.What 我做错了吗?

您在 post 操作中丢失了路线

//POST home/emailsignup
[Route("home/emailsignup")]
[HttpPost]
public ActionResult EmailSignup(string email) {
    //...
}

在控制器上使用属性路由时,您需要将其应用于所需的操作,否则会出现您已经遇到的 404 not found。