0

In ASP.Net 4, I could use Razor views as pure CSHTML without tying them to any MVC controller, basically I just wanted the lightweight layout and ability to call server side code when needed.

How do I do that in ASP.Net core? I've placed a CSHTML in wwwroot but the server won't serve it. Is there any particular service or provider I need to add into the startup class?

Thanks!

Marauderz
  • 1
  • 1

1 Answers1

1

There is no default controller. not in ASP.NET MVC 4 or Core. But what you can do is to create one. Simple ASP.NET MVC views without writing a controller

But what I'm actually assuming you're asking for is a .cshtml page that performs nothing, only HTML and Javascript (and with that make calls to partials, then again you need controllers). If that is what youre after then make a .html page in /wwwroot and not a .cshtml and enable static files in Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseStaticFiles();

and lastly, another thought, I think that you are not after MVC at all but rather ASP.NET Web Pages. By the looks of it the "asp.Net Web Pages" a.k.a loose cshtml looks to be dead in core, but a solution whould be a default controller on it.

Community
  • 1
  • 1
Thomas Andreè Wang
  • 3,379
  • 6
  • 37
  • 53
  • Yeah I'm not after static files, I want to use the centralized layout and other functionality of ASP.Net Web Pages (this is messed up and confusing :P) So it might work if I wire up a default controller? Let me check that out then. – Marauderz May 30 '16 at 10:01
  • @Marauderz Then you need a controller, it decides if you wire up the rest by returning `View` or just the content by returnning a `PartialView` from your controller – Thomas Andreè Wang May 30 '16 at 11:47