简体   繁体   中英

View in asp.net mvc3 is not visible

I'm trying to add a new view, 'Graph', to my asp.net mvc3 under the 'Home' folder.

When ia dd the view in and try to browse to the new view in a browser (xxx/Home/Graph) I get a URL not found error.

Not sure what I'm doing wrong to cause this, there is another view called 'About' in the same folder and that one is visible to the browser..

Views are not directly accessible in MVC. You need a controller and action method to serve up the view. Try adding an action method called Graph to your HomeController :

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

Also, if you want to serve up a view that doesn't have the same name as the action method, you can specifiy it directly:

public ActionResult SomethingOtherThanGraph ()
{
    return View ("Graph");
}

ASP.NET MVC works, by convention, by matching the action method's name to the view's name—unless you specify the view as in my second example.

Did you also create the Grapth action in your controller?

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

What is xxx in the path above? The path should be /Home/Graph or http://localhost/Home/Graph where a port number will be inserted after localhost.

Are you sure you have a action method called "Graph" in your "Home" controller ?

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

In MVC, the request xxxx/Home/Grpah means it will look for the Graph method in the Home controller. If you have a view present in your view/Home folder with name " Graph " , controller action will return that view.

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