开发者

Cannot debug views in MVC2 project, getting "The resource cannot be found" error

I'm running Visual Studio 2008 sp1 on Win7, with MVC2 RTM installed.

I created a new MVC2 project using the wizard and am unable to debug specific pages. With webforms and even MVC1, I was able to sit on a View page, hit F5, and then have the integrated web server in VS2008 start on the page I was working on. Very handy for building up app logic.

When I try this now I get a "The resource cannot be found" error page.

I retried this just now with a stock new MVC2 Web Application project. Here are the steps I took after creating the new project to reproduce:

  1. Open up project settings. Under the Web subtab, set the Start Action to "Current Page". Leave all the other settings as is.
  2. Open one of the views up (e.g. Account/Register.aspx)
  3. Hit F5 to debug the projec开发者_如何学编程t
  4. Note that the browser window which displays shows the error message "The resource cannot be found".

The link I saw in my browser for this run was: http://localhost:49471/Views/Account/Register.aspx

I did some googling and found suggestions related to ensuring all HTTP server pieces were installed. I double checked and made sure that "HTTP Errors" and "HTTP Redirection" were both installed.

If I leave the project setting as it was originally, set to "Specific Page" with nothing in the text box, then routing works and I always get the default home page. I'm hoping this isn't the only option.

Thanks!


Generally, the "resource cannot be found" (which is an HTTP 404) in ASP.NET MVC indicates some kind of routing problem.

Setting the Start Action to a page (any page) is probably why you're having this problem. AFAIK, this will always cause a 404 because MVC projects don't do pages, they do Actions.

Try clearing the Start Action- you should then see the Index action/view "page" come up when you run the project. Going forward, if you want to go to a particular Controller Action on startup, enter the [ControllerName]/[Action] in the Start Action without an .aspx page name.


Since I just found this link looking for the same class of answer, hopefully this will help since none actualy answered the question I had. If it's the same, here's what works:

VS, when you go to change the start-up page (by right mouse clicking the page and selecting "Set as Start Page") seems to put the path (in an MVC project) as if this was a regular old ASPX web app. The path you want in the project properties, when you want a specific page, is the path after the web server (usually when dev'ing: http:\localhost:####). So if you want your page "foo.aspx" or "foo.cshtml" (assume you're under "Home", you'll want to put Home\foo (no extensions).

This also assumes that your "Virtual Path" is set to "\".

Point is, you leave off 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 properties page should know how to make this happen. Consider this a request :)

But at least now you can test/dev the specific page.

HTH.


If you have copied the controller that you were using before adding areas to your project, doublecheck your namespace!


One reason this could occur is if you don't have a start page set under your web project's properties. So do this:

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 launch your web application, it will take you to the view rendered by the HomeController's Index action method.

(or)

Simply, you could also open one of the controllers in your project and then hit on F5 or Ctrl + F5.

What's happening now is that, you are currently in your /Views/home/Index.cshtml view and you just hit on F5 or Ctrl + F5. In an mvc project, you cannot open a file w/ .cshtml extension directly as IIS cannot understand that. The controller is supposed to return a matching view from within the action method.

As a side-note also check if you have MVC 3 installed correctly. If my answer doesn't help, I am sorry..

refernce code project

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜