创建了一个操作方法,但它仍然给出 "Http 404 error of missing url"

An action method is created but it still gives the "Http 404 error of missing url"

我已经创建了一个表单和一个保存按钮。我还创建了一个操作方法 CREATE,当我们单击 SAVE 按钮时将调用它。我现在想查看模型绑定,但是当我填写表单并单击保存按钮时,它显示以下错误消息。it shows the error message 请参阅附件代码

@using (Html.BeginForm("Create", "Customer"))
            {
                <div class="form-group">
                    @Html.LabelFor(m=>m.Customer.Name)
                    @Html.TextBoxFor(m=>m.Customer.Name, new { @class="form-control"})
                </div>

                <div class="form-group">
                    @Html.LabelFor(m=>m.Customer.BirthDate)
                    @Html.TextBoxFor(m=>m.Customer.BirthDate, new { @class="form-control"})
                </div>

                <div class="checkbox">
                    <label>
                        @Html.CheckBoxFor(m=>m.Customer.IsSubscribedToNewsLetter) Subscribed to Newsletter?
                    </label>
                </div>

                <div class="form-group">
                    @Html.LabelFor(m=>m.Customer.MembershipTypeId)
                   @*List of items*@
                    @Html.DropDownListFor(m=>m.Customer.MembershipTypeId, new SelectList(Model.MembershipTypes,"Id","Name"),"Select",new { @class="form-control"})
                </div>

                <button type="submit" class="btn btn-primary">Save</button>
}

下面是从控制器创建动作的方法

 [HttpPost]
    public ActionResult Create(Customer customer)
    {
        return View();
    }

尝试添加属性路由

[Route("~/customer/create")]
public ActionResult Create(Customer customer)

并在视图顶部添加模型

@model Customer

@using (Html.BeginForm("Create", "Customer", FormMethod.Post)) {

如果您使用的是 Net 4.8 或更早版本,则必须配置属性路由

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
 
    routes.MapMvcAttributeRoutes();
 
    routes.MapRoute(
        name: “Default”,
        url: “{controller}/{action}/{id}”,
        defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }
    );
}
````