1

i just strated with asp.net mvc. My doubt is in a controller we use

    public ActionResult Index()
    {
        return View();  

    }

so how a relevent view is returned for a particular controller.

4 Answers 4

3

Assuming a Home controller with an Index action here are the default search order locations:

ASP.NET MVC 2:

~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx

ASP.NET MVC 3:

~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Sign up to request clarification or add additional context in comments.

Comments

1

Any MVC tutorial will go over this in the first page or two. I would highly recommend you go through either the NerdDinnertutorial or Getting Started with MVC3 or possibly both.

To answer your question, that will return a view called Index in the Views folder that is named after your controller. In other words, if your view is named HomeController, that will return a view named Index in your Home views folder

Comments

0

The default route in ASP.Net MVC is http://.../Controller/Action. So when you are viewing Http://localhost/SomeController/Index, then ASP.Net MVC looks for Index.aspx in designated folders. If it does not find it, then you can see the exception on yellow page that it searched for Index.aspx and Index.ascx in Shared folder and a folder named on your controller.

All this is default behavior and ASP.Net MVC provides you extension points to change some or all of this behavior.

Comments

0

The name of the Function is used to find the name of the 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.