Noob question. I have a project with a self-hosted Web Api. I'm using the RazorEngine package so that I can serve up HTML pages using the views/razor scheme.
Within the HTML page there are links to .css, .JS, and images. How does the page get these embedded resources?
As I understand it, http://localhost:8080/api/home
in the browser causes the project to 'call' the page at /Views/Home.html
and pass through the Value
object. This results in HTML appearing in the browser rather than the usual JSON/XML that you normally get with WebAPi.
For the page to retrieve the embedded javascript, I guess I would create another WebApi controller that would respond to the URL, but how do I get it to transmit the javascript page? Ie how do I get it to look in a folder called 'Scripts' and not 'Views', not attempt to convert to HTML, and not bother with an associated model?
public class HomeController : ApiController
{
//http://localhost:8080/api/home
public Value GetValues()
{
return new Value() { Numbers = new int[] { 1, 2, 3 } };
}
}
[View("Home")]
public class Value
{
public int[] Numbers { get; set; }
}
home.cshtml...
<html>
<head>
<script src="/Scripts/script1.js"></script>
</head>
<body>
<img src="/Images/image1.png">
....
</body>
</html>