0

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

3 Answers 3

4

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.

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

Comments

2

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.

Comments

2

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.

Comments

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.