Unable to debug views in MVC2 project getting "Could not find resource" error
I am running Visual Studio 2008 sp1 on Win7, with RTM MVC2 installed.
I created a new MVC2 project using the wizard and cannot debug certain pages. With web forms and even MVC1, I was able to sit in the view page, press F5, and then start the integrated web server in VS2008 on the page I was working on. Very handy for creating application logic.
When I try this now, I get a "Resource not found" error page.
I have repeated this just now from a new MVC2 Web Application project. Here are the steps I took after creating a new project to reproduce:
- Open the project settings. In the Web Subrecord section, set the Action to Current Page. Leave all other settings as they are.
- Open one of the views to the top (for example, Account / Register.aspx)
- Hit F5 to debug the project
- Note that the displayed browser window displays a "Resource not found" error.
The link I saw in my browser for this run was: http: // localhost: 49471 / Views / Account / Register.aspx
I did some searches and found suggestions related to ensuring that all the components of the HTTP server are installed. I double checked and made sure the "HTTP Errors" and "HTTP Redirect" were set.
If I leave the project setting as it was originally, set to "Specific Page" which has nothing in the textbox, then routing works and I always get the default home page. I hope this is not the only option.
Thank!
source to share
Typically, "resource could not be found" (which is HTTP 404) in ASP.NET MVC indicates some sort of routing problem.
Setting the Start action on a page (on any page) is likely due to this issue. AFAIK, this will always throw a 404 because MVC projects don't make pages, they do actions.
Try to clear the Start Action - after that you should see the Action / View Pointer page when you start the project. If you want to jump to a specific controller action at startup, enter [ControllerName] / [Action] in the Start action without the .aspx page name.
source to share
Since I just found this link for looking for the same answer class, hopefully this helps as no one answered the question I had. If it's the same, here's what works:
VS, when you go to change the start page (by right clicking on the page and choosing Set as Start Page), it seems to put the path (in the MVC project) as if it were a normal old ASPX web application. The path you want in the project properties when you want to create a specific page is the path after the webserver (usually when dev'ing: http: \ localhost: ####). So if you want your page "foo.aspx" or "foo.cshtml" (assuming you are under "Home", you will need to put Home \ foo (no extensions).
This also assumes that your "virtual path" is set to "\".
The point is, you leave the folder and extension. Seems like a bug (aka: "feature under review") to me. Since the project type is MVC (either with aspx or cshtml pages), the project property sheet needs to know how to do this. Consider this request :)
But at least you can now check / dev for a specific page.
NTN.
source to share
One of the reasons for this can happen if you do not have a start page set in the properties of your web project. So do it:
Right click on your mvc project
Choose "Properties"
Select the "Web" tab
Select "Specific Page"
Assuming you have a controller called HomeController and an action method called Index, enter "home/index" in to the text box corresponding to the "Specific Page" radio button.
Now, if you run your web application, it will take you to the view displayed by the HomeController index action method.
(or)
It's just that you can also open one of the controllers in your project and then press F5 or Ctrl + F5.
What's happening now is that you are now in your /Views/home/Index.cshtml view and you just press F5 or Ctrl + F5. In the mvc project, you cannot open the .cshtml file directly as IIS cannot figure it out. The controller is expected to return the appropriate view from the action method.
As a side note, also check that MVC 3 is installed correctly. If my answer doesn't help, I'm sorry.
refernce project code
source to share