简体   繁体   中英

asp.net The resource cannot be found?

Well, i just created a new asp.net empty project with MVC and WebApi included

在此输入图像描述

The project is created and compiles successfully however, when i add anything in the views folder and try to view it in the browser i get IIS message HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

If you wanna reproduce such issue just do what i did and it will definitely occur (except if i am on some kind of drug that impaired my vision :D)

Are you sure you have added the controller that will intercept the request and will render the appropriate view? You cannot route the request directly to something you have inside your view folder. You need to have a controller and inside a controller you will have to add an action method that will you can use to return the view.

For ex. you have a controller named Home and in that you have an action method named Index, so when you will hit the following url: localhost/localApplication/Home/Index

It will execute the Index method of home controller and will return the view if it is designed to return a view else anything else and the correct method to add a view for an action is to right click inside the action source and select add view, which in above case will add the view in following location Views>Home>Index.cshtml (if its razor view) I hope this helps.

it won't work because if you are using MVC you need also add the controller. and then add a method returning the view you want to render example you add a controller named Home and if your Action in controller is as below

public ActionResult Index() { return View(); }

this will render the View named Index.cshtml which you have added in Views>>Home folder,you will need to add controller to Controller folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM