简体   繁体   中英

The Resource cannot be found . ASP.NET MVC

The resource cannot be found.

Requested URL: /Home/Home/Signup_User

However it should be /Home/Signup_User where Home is the controller and Signup_User is the function in Home Controller .I have checked the spelling its correct.

My Sign Up Form as follows.

<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 (with Controller and ActionName)

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

}

FormExtensions (with Controller , ActionName and Area )

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

}

代码快照

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

You just need to add Controller name slash action name, no need to add ~

Refer following code for Solution 1:

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

Else, use MVC's built in HTML helper to render the form and put your rest of the code into same.

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

Above code will generate empty tag.

One reason this could occur is if you don't have a start page set under your web project's properties. So do this:

Right click on your mvc project Choose "Properties" Select the "Web" tab Select "Specific Page" Assuming you have a controller called HomeController and an action method called Index, enter "home/index" in to the text box corresponding to the "Specific Page" radio button.

Now, if you launch your web application, it will take you to the view rendered by the HomeController's Index action method.

It seems you are using relative path in action URL . that's why Home Added twice like this.

/Home/Home/Signup_User

Asp.net MVC come up with beautiful Form Extensions .Just you need to specify Controller Name, Action Method Name and Area name if any.

for eg

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

In your case

ActionName :"Signup_User"
ControllerName:"Home"

Assuming, you don't have no area defined. replace your piece code with below snippet. it will resolve your issue.

CODE:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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