It is impossible to find a view, even if it is, it is not looking for the right extension

I am confused by this. I use a razor with MVC 3, and I have a problem with one view per action.

[HttpGet] [ActionName("Unsubscribe")] public ActionResult UnsubscribeGet(string maskedId) { return View("Unsubscribe", maskedId); } 

The Unsubscribe.cshtml view is in the correct view folder.

Route

 routes.MapRoute( "", // Route name "Unsubscribe/{maskedId}", // URL with parameters new { controller = "Account", action = "Unsubscribe" }); 

When you go to the next URL "/ Unsubscribe / db94fddb", the action starts, and then when you try to find the view, the following error is displayed.

The Unsubscribe view or its wizard was not found or the viewer does not support the locations found. The following locations were searched:
~ / Views / Account / Unsubscribe.aspx
~ / Views / Account / Unsubscribe.ascx
~ / Views / Shared / Unsubscribe.aspx
~ / Views / Shared / Unsubscribe.ascx
~ / Views / Account / db94fddb.master
~ / Views / Shared / db94fddb.master
~ / Views / Account / db94fddb.cshtml
~ / Views / Account / db94fddb.vbhtml
~ / Views / Shared / db94fddb.cshtml
~ / Views / Shared / db94fddb.vbhtml

Note that it does not look for the cshtml extension when searching for Unsubscribe, but when searching for db94fddb

This only happens with this view, completely at a loss how to fix it.

** EDIT **

Found,

I used System.String as a model. For some reason, it made him explode.

I changed it to @model UnsubscribeViewModel

 [HttpGet] [ActionName("Unsubscribe")] public ActionResult UnsubscribeGet(string maskedId) { return View("Unsubscribe", new UnsubscribeViewModel { MaskedId = maskedId } ); } 

Although it works now, I still donโ€™t know why it didnโ€™t work before. I have my views for compiling on an assembly, so there were no compiler errors.

I would like to know what is going on here.

+4
source share
1 answer

Overloading the View method you used takes two lines. He does not interpret the second line as a model, she interprets it as the name of the main page:

 protected internal ViewResult View( string viewName, string masterName ) 

If you call it this, it will work:

 return View("Unsubscribe", (object) maskedId); 
+11
source

Source: https://habr.com/ru/post/1390047/


All Articles