I am getting an error in developing a MVC4 Intranet application, trying to use multiple page layouts. As I see, the problem is not present when Internet application is used, here is quick demo.
Create new Internet application using Razor engine. Copy file _Layout.cshtml to Popup_Layout.cshtml (both in ~/Views/Shared), and strip header and footer sections in Popup_Layout. In ~/Controllers/HomeController.cs modify Index action with following code:
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
string layout = "_Layout";
if (DateTime.Now.Ticks % 2 == 1)
{
layout = "Popup_Layout";
}
return View("Index", layout);
}
That creates a simple game which randomly chooses to use one of two available page layouts. When compiled and tested, with refresh in browser we can see start page with or without header and footer sections.
Now if we repeat the exactly same scenario with only difference that project is Intranet application - build goes OK, but with refreshes in browser instead of getting a page without header and footer we get the server error, with the top of Stack trace says:
[InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Popup_Layout.master
~/Views/Shared/Popup_Layout.master
~/Views/Home/Popup_Layout.cshtml
~/Views/Home/Popup_Layout.vbhtml
~/Views/Shared/Popup_Layout.cshtml
~/Views/Shared/Popup_Layout.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +399386
As an alternative, layout can be determined in View itself with assignment ~/Views/Shared/Popup_Layout.cshtml to Layout property, but it also throws an error.
I didn't find the solution using web, so I hope someone can help me here. Thanks
Try deleting Popup_Layout.cshtml then instead of copy pasting the _Layout.cshtml create a new empty view page for Popup_Layout. After you have a new empty view page copy paste the content (if you wish). I don't know why but I tried it on my test project and it worked. I used a regular web app (not an intranet app) but I experienced the same missing view error you described.
I think the key is the way the view file was created. I copied the file and renamed it and seen the same error. When I properly created a new view and then copied in the content it all worked.
Dear noviKorisnik i tried to replicate your error as per you written here but i am not getting the error as you specified .
Your error first line is
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
I believe mistakenly you deleted the index.cshtml .
Please be sure you have index.cshtml in the right folder .if you still get the error please give more detail .
Related
I am currently adding a notification for our customers. They should be able to download a pdf with list of our branches. When I click on the link nothing happens. I don't understand why. I'm using standard MVC approach. I tried to look at the path that is stored in the variable and the file exists there.
Anything I'm missing here?
Edit:
when opening the link in new tab chrome puts "about:blank#blocked" in url (popups enabled)
Thanks for any input
#{
var path = Server.MapPath(#"~/ToolsModule/Content/Forms/PdfTemplates/PBS/ListOfBranches.pdf");
}
<div>
<div>you can find a link to list of all branches <b>here</b></div>
</div>
I'm playing around with umbraco for the first time. I've created my own test page and it displays perfectly fine.
When I go into Visual studio to edit the page as I would expect to (in this case just a little test). If Files to display in my page (I've check the source too can't see it?
I've tried a whole host of standard tag's such as p and h1 to get it to show. But so far its still not showing.
What am I missing?
#inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.WintyTest>
#using ContentModels = Umbraco.Web.PublishedModels;
#{
Layout = "contentPage.cshtml";
}
<text>this is a test is my hard coded string 3</text>
#Model.Value("bodyText")
I am trying to display images on my web api that are located on the server side.
for now I have added them in my solution in visual studio (I added two to try, I specified one as embedded ressource and one as none as build action. they are directly in WebAPISolution/xxx.png not in a subfolder
In my cshtml page, I put this:
<div>
<p>Test image</p>
<img id="img1" alt="Image1.png" src="#Url.Content("~/Image1.png")">
</div>
and on my web page it doesn't shows up.
it seems to look for it at:
view-source:https://xx.xx.xx.xx:5001/Image1.png
and the error message is
"can't be displayed because it contains error"
, it just doesn't find it I guess because the same with ImageXXX.png which doesn't exist return the same error
I don't get why the image doesn't shows up.
here is how is organized my solution folder
1 ) In your Startup Class you should add app.UseStaticFiles(); within public void Configure() method
2) Put your image in the wwwroot folder
3) add this code to your razor view <img src="~/Image1.png" />
I have an ASP.NET MVC solution which references to another class library, in which i have an MVC folder and inside of it "Controller", "Model" and "View" folders. I'd like to do something like
#Html.ActionLink("Text", "Index", "DllController")
which will link to the DllController/Index action in the dll and show a view from that lib. Debugging through this, I see that it goes into the Controller, but once it reaches
return View("MyView", model);
I receive the foolowing error:
The view 'MyView' or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/MyView/MyView.aspx
~/Views/MyView/MyView.ascx
~/Views/Shared/MyView.aspx
~/Views/Shared/MyView.ascx
~/Views/MyView/MyView.cshtml
~/Views/MyView/MyView.vbhtml
~/Views/Shared/MyView.cshtml
~/Views/Shared/MyView.vbhtml
~/Mvc/Views/MyView/MyView.cshtml
~/Mvc/Views/Shared/MyView.cshtml
I assume this is because the view is being searched for in the current assembly. Can i change this behavior to show my imported view correctly?
I have an MVC4 web application that i'm adjusting. Currently a controller loads Index.cshtml. In that file i have the following line:
#{
Layout = "~/Views/Shared/_Layout-DoubleColumn.cshtml";
}
So i changed that line to:
#{
Layout = "~/Views/Shared/_Layout-TripleColumn.cshtml";
}
I also copied to _Layout-DoubleColumn.cshtml file and renamed that to _Layout-TripleColumn.cshtml.
Now when i run the application i get the following error message:
The layout page "~/Views/Shared/_Layout-TripleColumn.cshtml" could not
be found at the following path:
"~/Views/Shared/_Layout-TripleColumn.cshtml"
I have no clue what the problem could be, because i'm sure that the file is in the Shared folder...
Anyone any idea what the problem could be?
Make sure the Build Action of the file is set to Content in the properties of the View.