2

So I just started at a new company and I'm trying to understand their code and it is quite complex. I am trying to debug a page and I know which view it is and I can set a break point in the view but I can't figure out which controller returned this view. How can I do this?

Recap: I can break in a view and I need to figure out what controller it came from.

2 Answers 2

2

If the application is using the Razor view engine (.cshtml files) you can use the following inside your view/layout to display the controller and action names:

@ViewContext.RouteData.Values["controller"].ToString()
@ViewContext.RouteData.Values["action"].ToString()

If it is using the WebForms view engine (.aspx files) you can do something similar with:

<%= RouteData.Values["controller"]%>
<%= RouteData.Values["action"]%>

The controller class will usually be named as in the route data plus "Controller". The action names will usually match a method name in the controller.

You may also consider getting a branch of the project just for you, and then install glimpse via Nuget. That may help you understand better the application.

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

Comments

0

Views usually are named after Controller action names. And views are placed in folders named after controllers.

Check this one for folder structure: http://www.codeproject.com/Articles/492833/ASP-NET-MVC-4-Part-2-Project-Items

Also you can set breakpoints in controllers and see which one is hit.

And I recommend watching free pluralsight course on MVC. I helped me a lot when I started with MVC.

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.