Last active
December 22, 2015 07:09
-
-
Save ianbattersby/6435993 to your computer and use it in GitHub Desktop.
Example Simple.web w/Razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<configSections /> | |
<appSettings> | |
<add key="webPages:Enabled" value="false" /> | |
<add key="ViewCache:Enabled" value="false" /> | |
<add key="ViewPath:Value" value="Views" /> | |
<add key="ViewRecursiveDiscovery:Enabled" value="true" /> | |
</appSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApplication26 | |
{ | |
using System; | |
using System.Collections.Generic; | |
using Simple.Web; | |
using Simple.Web.Behaviors; | |
internal class Program | |
{ | |
public static Type[] EnforceReferencesFor = { typeof(Simple.Web.Razor.AmbiguousViewException) }; | |
private static void Main(string[] args) | |
{ | |
new Simple.Web.Hosting.Self.OwinSelfHost().Run(); | |
} | |
} | |
public class IndexModel | |
{ | |
public string Message { get; set; } | |
} | |
[UriTemplate("/")] | |
public class GetIndex : IGet, IOutput<IEnumerable<IndexModel>> | |
{ | |
public Status Get() | |
{ | |
this.Output = new[] | |
{ | |
new IndexModel { Message = "Hi" }, | |
new IndexModel { Message = "From" }, | |
new IndexModel { Message = "Simple.Web" } | |
}; | |
return 200; | |
} | |
public IEnumerable<IndexModel> Output { get; private set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@handler ConsoleApplication26.GetIndex | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test page</title> | |
</head> | |
<body> | |
<div> | |
@foreach (var item in @Handler.Output) | |
{ | |
<p>@item.Message</p> | |
} | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model IEnumerable<ConsoleApplication26.IndexModel> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test page</title> | |
</head> | |
<body> | |
<div> | |
@foreach (var message in @Model) | |
{ | |
<p>@message</p> | |
} | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment