繁体   English   中英

无法找到该资源 。 ASP.NET MVC

[英]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>

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" }))
{

}

代码快照

尝试将action =“〜/ Home / Signup_User”替换为action =“ @ Url.Action(” Signup_User“,” Home“)”

您只需要添加Controller名称斜杠动作名称,无需添加〜

请参阅以下代码以获取解决方案1:

<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项目,选择“属性”,选择“ Web”标签,选择“特定页面”。假设您有一个名为HomeController的控制器和一个名为Index的操作方法,请在与“特定页面”单选按钮。

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

看来您在action URL中使用相对路径。 这就是为什么Home Add这样两次。

/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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM