Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio 2010, how do you invoke the "View In Browser" feature on an MVC app?

In Visual Studio 2010, you can right-click an aspx page in a web forms app, or on the web forms app itself in the solution explorer, and you get "View in Browser" in your context menu.

In ASP.NET MVC projects, this item doesn't seem to be available in the context menu. The only way I know to run the app is to set the MVC app as a startup project and hit CTRL+F5. But, if there are two MVC apps in the solution, this doesn't really work. How do you accomplish this for mvc apps?

like image 349
Chris Avatar asked Feb 15 '11 15:02

Chris


People also ask

What is the view in MVC API?

A view is used to display data using the model class object. The Views folder contains all the view files in the ASP.NET MVC application. A controller can have one or more action methods, and each action method can return a different view. In short, a controller can render one or more views.

How do I create a view in Visual Studio?

To create a new layout view in Visual Studio, right-click on the Shared folder -> select Add -> click on New Item... This will open the Add New Item popup, as shown below. In the Add New Item dialogue box, select MVC 5 Layout Page (Razor) template, and specify a layout view name as _myLayoutPage.

How do you add a view on razor?

Right click the Views\HelloWorld folder and click Add, then click MVC 5 View Page with Layout (Razor). In the Specify Name for Item dialog box, enter Index, and then click OK. In the Select a Layout Page dialog, accept the default _Layout. cshtml and click OK.

Can we run MVC in Visual Studio code?

Visual Studio Code (VS Code) allows you to create ASP.NET MVC application on Windows and Mac systems. To use C1 MVC controls, few additional steps are required to configure the project created using the Visual Studio Code IDE. Create a new folder on your system for the ASP.NET Core MVC application.


2 Answers

You really can't.

Routes are determined at runtime. There is no way for Visual Studio to know what View its going to use until routes are added, controller actions are hit and the ActionResult is executed.

like image 170
John Farrell Avatar answered Nov 15 '22 08:11

John Farrell


You can configure your web applications to use IIS so you don't have to hit F5 to run them. The IIS process will automatically start the web site for you. It's such a time saver!

  1. Right click a web project and choose Properties

  2. Go to the Web tab and choose the "Use Local IIS Web server" option.

  3. Enter a url like http://localhost/MyProject

  4. Rebuild.

  5. Navigate your browser to the url you entered.

If you want to debug your website, you can go to Debug > Attach to process..., then attach to w3wp.exe. This will attach to all web apps within your solution. (You might have to select the show processes from all uses option.) If you've just rebuild, you have to reload the site before IIS recycles and the breakpoints turn solid red. (If the breakpoints are ever only outlined in red that means the code running in IIS is an older build than what you are seeing. In rare cases you may have to kill the IIS process, but cleaning and rebuilding usually clears this up for me.)

Note: you'll probably have to go into Window's Programs and Features control panel and enable the IIS features. VS should prompt you if these aren't configured already.

like image 27
Ryan Avatar answered Nov 15 '22 07:11

Ryan