Helpfulinfo
Helpfulinfo

Reputation: 63

MVC adding View gets 404 not found

I want to copy DETAILS to make a 2nd details page. i click on the folder under Views, add..new item.. put in .cshtml in search then pick MVC View Page (Razor), name it R3, Add.

it opens with basic html framework and says @{ layout=null} ? ok i open Details, select all, copy and paste in R3. save. run. error:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

ok

HTTP Error 400.0 - Bad Request Bad Request

put /Details/1 sometimes it works.

is this a limitation in MVC? you cannot show the details page directly?

Upvotes: 1

Views: 8365

Answers (3)

Gratzy
Gratzy

Reputation: 2908

jfeston helped me out a bit. However, I had the method in my controller BUT I had [HttpPost] as part of the method header. I needed to create another method with [HttpPost] to accept requests from the new view.

So...

[AllowAnonymous] // this is a login page; there is no auth yet
public ActionResult Login()
{
    // do stuff here
}

[AllowAnonymous]  
[HttpPost]  // this accepts the request from the view
public ActionResult Login(User user, string returnURL)
{
    // do stuff here
}

Upvotes: 0

jfeston
jfeston

Reputation: 1562

Remember this is MVC. The request goes to the controller, where an action is performed and the result is shown in a view. You created a new view file, but there is no reference in the controller.

The default routing mechanism looks for a controller and then an action in the controller to fulfill a request. You should create an action named R3, with the same code as the action Details and try again.

Upvotes: 11

Jeff
Jeff

Reputation: 2313

It doesn't sound like you have an action responsible for populating the model requred for R3 to display.

If you copy the Details action and rename it R3, it should work.

Upvotes: 1

Related Questions