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 w开发者_运维技巧eb 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?
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.
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!
Right click a web project and choose Properties
Go to the Web tab and choose the "Use Local IIS Web server" option.
Enter a url like http://localhost/MyProject
Rebuild.
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.
精彩评论