The view or its wizard was not found or the viewer does not support the locations found

Error: browsing "LoginRegister" or its wizard was not found or the browsing mechanism does not support the found locations. The following locations were searched:

~ / Views / MyAccount / LoginRegister.aspx

~ / Views / MyAccount / LoginRegister.ascx

~ / Views / Shared / LoginRegister.aspx

~ / Views / Shared / LoginRegister.ascx

~ / Views / MyAccount / LoginRegister.cshtml

~ / Views / MyAccount / LoginRegister.vbhtml

~ / Views / Shared / LoginRegister.cshtml

~ / Views / Shared / LoginRegister.vbhtml

Actually my pageview page is ~/Views/home/LoginRegister.cshtml , so what I do

and my RouteConfig is

  public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "MyAccount", action = "LoginRegister", id = UrlParameter.Optional } ); } } 
+72
asp.net-mvc-4
Aug 16 '13 at 12:32
source share
14 answers

Be careful if your model type is String , because the second View (string, string) parameter is masterName, not the model . You may need to call overload with the object (model) as the second parameter:

Wrong:

 protected ActionResult ShowMessageResult(string msg) { return View("Message",msg); } 

Right:

 protected ActionResult ShowMessageResult(string msg) { return View("Message",(object)msg); } 

OR (provided by bradlis7):

 protected ActionResult ShowMessageResult(string msg) { return View("Message",model:msg); } 
+95
Jul 06 '15 at 12:18
source share

Problem:

Your View cannot be found in the default locations.

Explanation:

Views must be in the same folder as Controller or in the Shared folder.

Decision:

Move your View to the MyAccount folder or create a HomeController .

Alternatives:

If you do not want to move the View or create a new Controller , you can check the link.

+28
Aug 16 '13 at 12:34 on
source share

In Microsoft ASP.net MVC, the routing mechanism used to parse incoming and outgoing URLs is designed with the idea of ​​convention in configuration. This means that if you follow the rules (rules) that the routing mechanism uses, you do not need to change the configuration.

The routing mechanism for ASP.net MVC does not serve web pages (.cshtml). It provides a way for a URL to process a class in your code that can display text / html in the output stream, or parse and serve .cshtml files in a consistent manner using the Convention.

The convention used for routing must correspond to a controller for a class with a name similar to ControllerNameController ie controller="MyAccount" means looking for a class named MyAccountController . Next comes the action that maps to a function in the controller class, which usually returns an ActionResult . those. action="LoginRegister" will look for the public ActionResult LoginRegister(){} function in the controller class. This function can return View() , which would be in accordance with the Convention with the name LoginRegister.cshtml and would be stored in the folder /Views/MyAccount/ .

To summarize, you will get the following code:

/Controllers/MyAccountController.cs:

 public class MyAccountController : Controller { public ActionResult LoginRegister() { return View(); } } 

/Views/MyAccount/LoginRegister.cshtml: your view file.

+12
Aug 16 '13 at 13:13
source share

In the LoginRegister action when returning the view, do it below, I know that this can be done in mvc 5, im not sure what it is in mvc 4 either.

  public ActionResult Index() { return View("~/Views/home/LoginRegister.cshtml"); } 
+6
Aug 21 '15 at 18:10
source share

This may be a permission issue.

I have had the same issue recently. As a test, I created a simple hello.html page. When I tried to download it, I got an error message. As soon as I fixed the problem with permissions in the root folder, the problems with the html page and MVC rendering were fixed.

+3
Aug 21 '15 at 17:46
source share

Check if the view file (.ASPX) that you created has the same name as the controller. For example, for example:

  public ActionResult GetView() { return View("MyView"); } 

In this case, the aspx file should be named MyView.aspx instead of GetView.aspx

+2
Jul 22 '15 at 7:58
source share

I got this error because I renamed my view (and the POST action).

Finally, I found that I forgot to rename BOTH GET and POST to a new name.

Solution : Rename both the GET and POST actions to match the view name.

+2
Feb 16 '16 at 21:25
source share

Check the build action of your view (.cshtml file). It must be set as content. In some cases, I saw that the assembly action was set to β€œNo” (by mistake), and this particular view was not deployed to the target machine, even if you see that the view is present in the visual studio project file in a valid folder

+2
May 7 '17 at 17:23
source share

If the problem occurs periodically during production, this may be due to interruption. For example, during a POST operation associated with a large file download, the user closes the browser window before completing the download. In this case, the action method may cause a null reference exception obtained from the null model or viewer. The solution would be to wrap the body of the method in try / catch and return null. Like this:

 [HttpPost] public ActionResult Post(...) { try { ... } catch (NullReferenceException ex) // could happen if POST is interrupted { // perhaps log a warning here return null; } return View(model); } 
+1
Feb 10 '17 at 20:25
source share

If you checked all the things from the above answers (which are common errors) and you are sure that your view is in place in the exceptions, you may need to restart Visual Studio.

: (

0
Oct 12 '15 at 10:38
source share

I had the same problem. I copied the Cinema view and renamed it Client accordingly. I also did the same with models and controllers.

The solution was this ... I renamed the customer view to Customer1, just created a new view and named it Customer .... Then I just copied Customer1 code into Customer.

It worked.

I would like to know the real cause of the problem.

UPDATE Only for smirks .... I came back and repeated the whole renaming script again ... and did not get any errors.

0
Apr 05 '19 at 23:44 on
source share

In my case, I needed to use RedirectToAction to solve the problem.

 [HttpGet] [ControleDeAcessoAuthorize("Report/ExportToPDF")] public ActionResult ExportToPDF(int id, string month, string output) { try { // Validate if (output != "PDF") { throw new Exception("Invalid output."); } else { ...// code to generate report in PDF format } } catch (Exception ex) { return RedirectToAction("Error"); } } [ControleDeAcessoAuthorize("Report/Error")] public ActionResult Error() { return View(); } 
0
Aug 19 '19 at 13:01
source share

I came across this a while ago, and it drove me crazy because it turned out to be simple. Therefore, in my View, I used a grid control that received data for the grid through an http request. When the middle tier completed my query and returned the data set, I got the same error. Turns out my return statement was 'return View (dataset);' instead of 'return Json (data set);

0
Aug 27 '19 at 11:23
source share

There are several policies in my work that do not make NuGet work at all, and as a result my solution has lost its links to the microsoft.aspnet.mvc DLL. However, as soon as I added the DLL to the links manually, I was able to display the page.

-3
Feb 23 '17 at 21:28
source share



All Articles