无法找到该资源 。 ASP.NETMVC

The Resource cannot be found . ASP.NET MVC

找不到资源。

Requested URL: /Home/Home/Signup_User

不过应该是/Home/Signup_User 其中 Home 是控制器,Signup_UserHome Controller 中的函数。我检查了拼写是否正确。

我的注册表如下。

<form action="~/Home/Signup_User" method="post" enctype="multipart/form-data">
    @Html.AntiForgeryToken()

    <div class="row">
        <div class="large-6 columns">
            <label>
                Enter Name
                @Html.EditorFor(model => model.username, new { htmlAttributes = new { @class = "form-control" } })
            </label>
        </div>
        <div class="large-6 columns">
            <label>
                Enter Age
                @Html.EditorFor(model => model.age, new { htmlAttributes = new { @class = "form-control" } })
            </label>
        </div>
        <div class="large-6 columns">
            <label>
                Enter Email Address
                @Html.TextBoxFor(model => model.email, new { @class = "large-12", placeholder = "xyz@gmail.com", type = "email" })
            </label>
        </div>
        <div class="large-6 columns">
            <label>
                Enter Password
                @Html.PasswordFor(model => model.password, new { })
            </label>
        </div>
    </div>
    <br />
    <hr />
    <button type="submit" class="button tiny right" style="margin-left:5px;color:white;">Submit</button>
    <a href="#" class="button secondary tiny right close-reveal-modal" style="position:relative;    font-size: 0.6875rem;color:inherit;top:0;right:0;   font-weight: 300;" aria-label="Close">Cancel</a> }
    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
</form>

尝试更换 行动=“~/Home/Signup_User” 和 action="@Url.Action("Signup_User", "Home")"

FormExtensions(带有 Controller 和 ActionName)

@using (Html.BeginForm("Signup_User", "Home", FormMethod.Post))
{

}

FormExtensions(带有 Controller 、 ActionName 和 Area )

@using (Html.BeginForm("Signup_User", "Home", FormMethod.Post, new { area = "AreaName" }))
{

}

你只需要添加控制器名称斜线动作名称,无需添加~

方案一参考以下代码:

<form action="/Home/Signup_User" method="post" enctype="multipart/form-data">
    //Add rest of your code
</form>

否则,使用 MVC 的内置 HTML 助手来呈现表单并将其余代码放入其中。

@using (Html.BeginForm("Signup_User", "Home", FormMethod.Post))
{
  // Add your rest of code
}

以上代码将生成空标签。

发生这种情况的一个原因是您没有在 Web 项目的属性下设置起始页。所以这样做:

右键单击您的 mvc 项目 选择 "Properties" Select "Web" 选项卡 Select "Specific Page" 假设您有一个名为 HomeController 的控制器和一个名为 Index 的操作方法,请在 "Specific Page" 单选按钮对应的文本框中输入 "home/index"。

现在,如果您启动 Web 应用程序,它将带您到 HomeController 的 Index 操作方法呈现的视图。

您似乎在 action URL 中使用了相对路径。这就是为什么 Home 像这样添加了两次。

/Home/Home/Signup_User

Asp.net MVC想出漂亮的Form Extensions。只需要指定Controller Name,Action Method NameArea name即可

例如

@using (Html.BeginForm("actionName", "controllerName", new {area = "AreaName"}))

你的情况

ActionName :"Signup_User"
ControllerName:"Home"

假设您没有定义区域。用下面的代码片段替换你的代码。它会解决你的问题。

代码:

@using (Html.BeginForm("Signup_User", "Home"))
        @Html.AntiForgeryToken()

        <div class="row">
            <div class="large-6 columns">
                <label>
                    Enter Name
                    @Html.EditorFor(model => model.username, new { htmlAttributes = new { @class = "form-control" } })
                </label>
            </div>
            <div class="large-6 columns">
                <label>
                    Enter Age
                    @Html.EditorFor(model => model.age, new { htmlAttributes = new { @class = "form-control" } })
                </label>
            </div>
            <div class="large-6 columns">
                <label>
                    Enter Email Address
                    @Html.TextBoxFor(model => model.email, new { @class = "large-12", placeholder = "xyz@gmail.com", type = "email" })
                </label>
            </div>
            <div class="large-6 columns">
                <label>
                    Enter Password
                    @Html.PasswordFor(model => model.password, new { })
                </label>
            </div>
        </div>
        <br />
        <hr />
        <button type="submit" class="button tiny right" style="margin-left:5px;color:white;">Submit</button>
        <a href="#" class="button secondary tiny right close-reveal-modal" style="position:relative;    font-size: 0.6875rem;color:inherit;top:0;right:0;   font-weight: 300;" aria-label="Close">Cancel</a> }
        <a class="close-reveal-modal" aria-label="Close">&#215;</a>
    </form>