0

I currently get the error "The Resource cannot be found" when trying to access a View.

The View I am trying to open is called "Register". The Controller(AccountController) has the ActionResult Method "Register" implemented.

The same Controller contains a "Login" View that I can access without any problems.

The URLS I am trying to call:

localhost:port/Account/Login <- Works localhost:port/Account/Register <- Doesnt work

Controller Method:

    [HttpPost]
    public ActionResult Register(LoginModel model)
    {
        if(ModelState.IsValid)
        {
            movieEntities db = new movieEntities();
            var newUser = db.users.Create();
            var encrypPass = Helpers.SHA256.Encode(model.Passwort);
            var user = model.UserName;
            newUser.user_name = user;
            newUser.user_passwdhash = encrypPass;
            db.users.Add(newUser);
            db.SaveChanges();
            return RedirectToAction("Index", "Home");
        }
        return View(model);
    }

View:

@model MovieDatabase.Models.LoginModel

@{
ViewBag.Title = "Register";
}

<h2>Register</h2>


@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>LoginModel</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class 
    = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.UserName, new { htmlAttributes = 
    new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Passwort, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Passwort, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Passwort, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Register="btn btn-default" />
        </div>
    </div>
</div>
}
    @section Scripts {
         @Scripts.Render("~/bundles/jqueryval")
    } 

I tried cleaning, rebuilding the solution, renaming the View, renaming the method and creating them new... What am I missing here?

1 Answer 1

1

It seems that your method that you're calling is POST back try to create another method that will return the view that you are referring to. Add this on your code.

 public ActionResult Register()
 {
    return View();
 }

The file name of the view is same of the name of your method. If not you're getting the same error.

For more info in routing kindly refer to Microsoft documentation ASP.NET MVC Routing

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! i didnt think of that... Fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.