0

I'm developing a single page application using angularJs with a layout page that will be available for all my pages, but now I want some pages to be loaded without the layout page included in it, how can I do that. Any idea on this. Remember my pages are not @razor rendered with .cshtml except the layout and the index page all the other pages in my app are .html files.

Index.cshtml:

<div data-ng-view></div> - This is where all my pages will get loaded in to using the ngRoute

_Layout.cshtml:

<body>
<aside><nav>....</nav></aside>
<section><header>...</header>RenderBody()</section> - This is where my index page gets called
<aside>....</aside>
</body>

Now, I would like to get my page still loaded through the #index as my application is SPA, but _Layout.cshtml should be ignored.

Ajay Srikanth
  • 1,095
  • 4
  • 22
  • 43

1 Answers1

0

Any *.cshtml pages are rendered server side and then served to the client.

*.html pages are statically served to the client.

Usually any static resources are put in the "Content" folder. In my own personal project this is where I put my static html pages.

In other words, you are in fact using Razor. In this case, using a different _layout.cshtml is answered in this stackoverflow question:

How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

Also, usually, in general, for an SPA app, data is served asynchronously through a REST API or a REST/JSON API. In which case, once you're layout is loaded client side, you shouldn't have to deal with *.cshtml files, you should only have to deal with pure data and your javascript on the client side takes care of rendering that data into html.

In my personal project, I have a HomeController that serves a static html page:

public class HomeController : Controller
{

   public ActionResult Index()
   {
       return Redirect(Url.Content("~/Content/index.html"));
   }

}

What happens here is that when the user goes to http://localhost/ it executes the Index action from the HomeController which redirects to a static html file that contains my layout.

Any requests after that are loaded using Ajax requests that return JSON data. In other words, for any following requests, I don't have to deal with Razor "*.cshtml" files.

You shouldn't need to "ignore" _layout.cshtml since you're suppose to be serving just data.

Community
  • 1
  • 1
TchiYuan
  • 4,258
  • 5
  • 28
  • 35
  • Hi Yuan, I guess you didn't understand my question here. I know .cshtml files are all served by the server and hence I can control which Layout page it should use, but my application being angularJS with SPA and all are html pages, how can I exclude the default layout page for certain pages where I don't want the layout. – Ajay Srikanth May 27 '15 at 16:37