views:

471

answers:

1

Hi,

I just created a ASP.NET MVC project in VS2008.

When I press F5 to debug the current view in my browser, it open the URL of the ASPX file :

http://localhost/Views/MyController/Index.aspx

instead of :

http://localhost/MyController

How to make it open the good URL ?

+8  A: 

You've got start action set to Current Page in the Web tab of the project properties.

Change it to Specific Page and leave the specific page text box blank.

Edit: from the comments attached to this answer we've established that what would be desirable is for VS to heursitically determine that given that the current page in the editor is "Views/Products/Index.aspx" we would like VS to start a debugging session at /Products.

This is too much to be asking of VS right now.

The alternative might seem to always be starting from the root and navigating in.

However you can edit the Specific Page text box to the path you'd like it to start. If you are debugging the above view then entering "Products" in the text box would probably be the closest you'd get to the goal.

You'd have to keep changing the content of the Specific Page text box each time you want to repeatedly test a different view.

AnthonyWJones
With your solution, it always opens the home page (http://localhost).I'd like VS to open the controller of my current view : if I work on the /Views/MyController/Index.aspx file, I'd like it to open http://localhost/MyController
Olivier PAYEN
Why are your controllers inside your Views folder? Normally, controllers live in the Controllers folder.
tvanfosson
Actually, I'm not sure that this is even doable. What you want is to open a route that corresponds to a controller action not a view. The view is chosen by the controller. Opening up a particular view absent the associated route information makes no sense.
tvanfosson
Sorry for the misunderstanding, my controllers live in the Controllers folder.Here is another example : when I work on the /Views/Products/Index.aspx file, which is the View of the ProductsController controller, I want VS to open http://localhost/Products
Olivier PAYEN
@tvanfosson, I understand but I thought that in ASP.NET MVC, if no action is indicated, it executes the Index() action of the controller ?
Olivier PAYEN
@Olivier: That is actually quite a big ask. What if the current view represents a controller action which requires further parameters to make any sense? I agree this is a nice to have but its quite a bit harder than it seems.
AnthonyWJones
Which action is default is down to the routes specified in the Global.asax.cs, it may not be index(), resolving all this is a lot to ask of VS which is only barely concious of MVC existance.
AnthonyWJones
Ok, I understand. So when I want to debug a view, I need to open my website to the default page and then browse to this view every time ?
Olivier PAYEN
I'd like to at least get always the root open, but the URI field doesn't allow me to leave it empty or put a relative URI like /. How do you get localhost open all the time?
J. Pablo Fernández