I've searched around for a few days now and can't seem to find the proper solution for my problem. I'm pretty sure it has something to do with routing however i'm not sure exactly.
The Exact error that i'm receiving is:
The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Stack Trace:
[InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +502
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +143
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +90
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
I'm getting this error on every single page that I have in my web application, however my homepage is working regardless of if I do the URL or if I type /Home/Index.
Inside of my Controller method name matches my View name
public ActionResult Reporting()
{
var model = new DashboardCurrentRelease
{
ApplicationNames = GetApplications()
};
return View("Reporting", (object)model);
}
And the GetApplications() method looks like this:
private IEnumerable<SelectListItem> GetApplications()
{
var applications = new DashboardViewModel();
var applicationList = applications.DashboardCurrentReleases.Select(x => new SelectListItem
{
Value = x.ApplicationName.ToString(),
Text = x.ApplicationName
});
return new SelectList(applicationList, "Value", "Text");
}
Here is what my model looks like:
public partial class DashboardViewModel : DbContext
{
public DashboardViewModel()
: base("name=DashboardViewModel1")
{
}
public virtual DbSet<DashboardCurrentRelease> DashboardCurrentReleases { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.ApplicationName)
.IsUnicode(false);
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.Release)
.IsUnicode(false);
}
}
[Table("DashboardCurrentRelease")]
public partial class DashboardCurrentRelease
{
[Display(Name = "Application Name")]
public IEnumerable<SelectListItem> ApplicationNames { get; set; }
[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ApplicationKey { get; set; }
[StringLength(50)]
public string ApplicationName { get; set; }
[StringLength(50)]
public string Release { get; set; }
public int? FailCnt { get; set; }
public int? PassCnt { get; set; }
public int? OtherCnt { get; set; }
public int? ExecutedCnt { get; set; }
public int? NotExecutedCnt { get; set; }
}
And my routingconfig file looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
Are there any ideas on how to fix my problem? Am I Not doing my RouteConfig correctly? I read that it has to be the least specific routes first and then the most specific ones after that but it still doesn't want to work for me.
One more Route Config that I have tried without success is also this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Reporting", "{controller}/{action}",
new
{
controller = "Reporting",
action = "Reporting"
});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
I should mention that I have set all of the Properties of each of my View Pages To a Build Action of Content which they were 'None' before but that also did not fix the issue.
Edit: I forgot to mention, it works perfectly fine when I'm debugging in my local environment, it's when trying to run on a webserver that it starts breaking.
Edit 2: I've added the stack trace to my initial question as well as the model and a few touchups here and there.
Edit 3: One last thing is that to get to the page I've tried to do it from the view in 2 different ways. The first way is doing:
@Html.ActionLink("Report Details", "Reporting", "Reporting")
And the second is doing:
<a href="../Reporting/Reporting">
<span>Report Details</span>
</a>
In MVC, the routing engine, which is used to parse incoming and outgoing URL Combinations, if you follow the Convention (rules) that the routing engine uses, you don't have to change the Configuration. I really only use custom routes for areas or anything outside the convention of MVC. And the convention you have seems to follow the guidelines of MVC with folder and controller matching each other. so i do not believe you need a custom route.
The routing engine for ASP.net MVC does not serve web pages (.cshtml). It provides a way for a URL to be handled by a Class in your code, which can render text/html to the output stream, or parse and serve the .cshtml files in a consistent manner using Convention. Your View engine is what provides the web pages (.cshtml) file from the directory named after the controller. This being said the routing engine controls the URL. Have you tried **return View("NameOfView", Model);**
You need to watch for other things, like Make sure the namespaces are correct and if you are you obtaining a string from your model? of you are it must be properly formatted like return View("Message",(object)msg);
and not return View("Message",msg);
as i can not see your model, or your view, and the complete stack trace is not posted its really hard to say why your view is not showing. it would also be nice if you had show a URL that was being called with changed names of course. but the main thing i can think of is the model, and or namespaces, Also if you are calling the Layout = "~/Views/Shared/_Layout.cshtml";
from your view or are you dependent on the _ViewStart
file. Also check that you are calling the correct action from you menu, or link. The @Html.Action
method actually invokes a controller and renders the view, Have you tried to use intellisense to look at the overloads for ActionLink, (@Html.ActionLink("Some text","Action","Controller", new {id=1}, null)
), just to make sure your calling the correct action from the link. Hope this kind of points you in the right direction to a solution.