EDIT: Sorry, thought I posted this in the MVC forums. If it needs to move then that's cool
Hello:
I am working with asp.net MVC4 (I think) and I have an issue. When I start my project it will render the styling just fine on the home page, but when navigate to any other page, the styling is missing. Here is my code, please let me know if there's something
else you would like to see:
Controller, which works fine:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SchmuckSports.Controllers
{
public class HomeController : Controller
{
public ActionResult HomePage()
{
return View();
}
public ActionResult Stats()
{
return View();
}
}
}
My _Layout.cshtml (sorry so long, I have some views with special objects and such):
When the project loads, the routeconfig points to the Home controller -> HomePage. When you put in the URL of the entry point, it works just fine. Since I am just running locally right now, the URL is: http://localhost:61475/ So
as I said, doing that will get me the view styled properly.
You can set the Layout property in the individual view also, to override default layout page setting of
_ViewStart.cshtml.
_ViewStart.cshtml file can be used to specify path of layout page, which in turn will be applicable to all the views of the folder and its subfolder.
Use Layout View:
For example, the following _ViewStart.cshtml in the Views folder, sets the Layout property to "~/Views/Shared/_Layout.cshtml". So now,
_layout.cshtml would be layout view of all the views included in Views and its subfolders. So by default, all the views derived default layout page from
_ViewStart.cshtml of Views folder.
Setting Layout property in individual view:
You can also override default layout page set by _ViewStart.cshtml by setting Layout property in each individual .cshtml view. For example, the following Index view use
_myLayoutPage.cshtml even if _ViewStart.cshtml set
_Layout.cshtml.
This should be the error point.please find BundleConfig.cs file and modify
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
... bundles.Add(new StyleBundle("~/Content1/content2").Include("~/Content/...css"));
bundles.Add(new StyleBundle("~/Content1/css").Include("~/Content/....css"));
Reason: the virtual path name(StyleBundle("~/Content1/content2"))
should different with the exist folder name or file name, can't contain;
With regards, Angelina Jolie
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
thanks Angelina. Still didn't work for me, but has me looking at my bundleConfig more closely, because these paths don't appear to have the files needed in them. Let me toy with it a bit and get back to this thread with what I find.
Member
6 Points
17 Posts
Styles not applying to views other than home view
Nov 21, 2017 12:36 AM|kenneth2k1|LINK
EDIT: Sorry, thought I posted this in the MVC forums. If it needs to move then that's cool
Hello:
I am working with asp.net MVC4 (I think) and I have an issue. When I start my project it will render the styling just fine on the home page, but when navigate to any other page, the styling is missing. Here is my code, please let me know if there's something else you would like to see:
Controller, which works fine:
My _Layout.cshtml (sorry so long, I have some views with special objects and such):
And for simplicity sake I have a couple of really simple views that the @url.action links point to:
Home view
Stats view
So this all works fine, but here's what I notice:
When the project loads, the routeconfig points to the Home controller -> HomePage. When you put in the URL of the entry point, it works just fine. Since I am just running locally right now, the URL is: http://localhost:61475/ So as I said, doing that will get me the view styled properly.
But let's say I navigate to http://localhost:61475/Home/Stats
or even http://localhost:61475/Home/HomePage (which I figured would render the same as http://localhost:61475/ )
then I will lose my styling. The page displays with just un-styled html. What am I missing? Thanks for any help you can provide.
Participant
990 Points
475 Posts
Re: Styles not applying to views other than home view
Nov 21, 2017 01:47 AM|zxj|LINK
Hi Kenneth2k1,
You can set the Layout property in the individual view also, to override default layout page setting of
_ViewStart.cshtml
._ViewStart.cshtml
file can be used to specify path of layout page, which in turn will be applicable to all the views of the folder and its subfolder.Use Layout View:
For example, the following
_ViewStart.cshtml
in the Views folder, sets the Layout property to "~/Views/Shared/_Layout.cshtml
". So now,_layout.cshtml
would be layout view of all the views included in Views and its subfolders. So by default, all the views derived default layout page from_ViewStart.cshtml
of Views folder.Setting Layout property in individual view:
You can also override default layout page set by
_ViewStart.cshtml
by setting Layout property in each individual .cshtml view. For example, the following Index view use_myLayoutPage.cshtml
even if_ViewStart.cshtml
set_Layout.cshtml
.Regards,
zxj
Member
6 Points
17 Posts
Re: Styles not applying to views other than home view
Nov 21, 2017 04:34 AM|kenneth2k1|LINK
Hello zxj. This is what is confusing me, because I already have my _ViewStart.cshtml set exactly as you have posted.
why would my styling get applied on the entry point, but navigating to other pages have the styling not applied?
Even if I change my RouteConfig to:
then that view will display with styling when the site is run, but navigating to /Home/HomePage won't have styling.
Contributor
5290 Points
2307 Posts
Re: Styles not applying to views other than home view
Nov 21, 2017 10:14 AM|AngelinaJolie|LINK
Hi kenneth,
This should be the error point.please find BundleConfig.cs file and modify
Then at_layout page:
Change to:
Reason: the virtual path name(StyleBundle("~/Content1/content2")) should different with the exist folder name or file name, can't contain;
With regards, Angelina Jolie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
17 Posts
Re: Styles not applying to views other than home view
Nov 21, 2017 05:24 PM|kenneth2k1|LINK
thanks Angelina. Still didn't work for me, but has me looking at my bundleConfig more closely, because these paths don't appear to have the files needed in them. Let me toy with it a bit and get back to this thread with what I find.
Member
6 Points
17 Posts
Re: Styles not applying to views other than home view
Nov 21, 2017 07:33 PM|kenneth2k1|LINK
Thanks again, checked my bundles and needed to update my _Layout.cshtml to render those scripts/styles:
Thanks again for the help.