-1

I working on an ASP.NET Core project. Is there any way that I can manipulate html, css, or javascript that is in my wwwwroot file?

For example I have class Uptime, that only contain property that return true or false. Is there any way that I can change for example css in my html page (if is true I want for example to change color to red of my element in html(css)).

jps
  • 20,041
  • 15
  • 75
  • 79
Aleksandra
  • 91
  • 2
  • 2
  • 7
  • Why don't you just change css prop/class for element depending on `Uptime` property? You can do it via js or even render already prepared markup. – AlbertK Feb 08 '18 at 08:43
  • I put that as example, I will get data from database and c# class, how to manipulate with html under the wwwroot, is there any way? – Aleksandra Feb 08 '18 at 08:49

2 Answers2

1

One way to include the CSS files in @section in the View and set a condition on the model property value.

@model ColorViewModel
@section styles{
@if(Model.IsRed)
{
<link href="~/css/red.css" rel="stylesheet" />
}
else
{
<link href="~/css/green.css" rel="stylesheet" />
}
}
Steve Tolba
  • 1,417
  • 1
  • 10
  • 11
0

I beleive that there is no special API for manipulating wwwroot folder in asp.net core. So you can use a common System.IO.FileSystem package.

Note: I wouldn't recommend to use this approach for your needs. Static files should be static. You need to consider change css prop/class for element depending on Uptime property via javascript or return prepared markup/css/js from your controler.

AlbertK
  • 11,841
  • 5
  • 40
  • 36