Willy
Willy

Reputation: 1729

How to fix the Url (~/Views/Home/Index.cshtml) when run from view

I'm using MVC 4 VS 2012 Express for Web to develop a site. Usually when I directly run from the view, for example Index View in Home Controller, I got 'http://localhost:62335/' on the url address bar, but now I got http://localhost:62335/Views/Home/Index.cshtml

I don't change the routing on RouteConfig class, as you can see in the code below

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

Why this could happen and how to fix it?

Upvotes: 0

Views: 11730

Answers (3)

erden sarıgül
erden sarıgül

Reputation: 1

  1. Project rigth click > Properties
  2. click to Web
  3. Select "Current Page" and Save

enter image description here

Upvotes: 0

FLICKER
FLICKER

Reputation: 6683

I post this answer to make a clear answer and find it easier

As answered in ASP.Net MVC – Resource Cannot be found error

You should go to Project Properties then Web Tab and leave it blank.

I'm wondering why we should fiax it manually!

Upvotes: 0

Ash
Ash

Reputation: 2595

Try to call the controller instead :

http://localhost:62335/Home/

Go to your project's properties and set the start page property.

  • Go to the project's Properties

  • Go to the Web tab

  • Select the Specific Page radio button
  • Type in the desired url in the Specific Page text box i.e. http://localhost:62335/Home/

Upvotes: 6

Related Questions