You can serialize an F#/C# value to JSON using Content.Json:

1
2
3
4
5
6
7
8
9
type Person =
    {
        Name: string
        Age: int
    }

let john = { Name="John Smith"; Age=40; }

Content.Json john

Sometimes, you may want to return a string (say, content) as JSON, for instance if you used a third-party JSON serializer:

1
2
Content.Text content
|> WithContentType "application/json"
By on 10/20/2017 5:12 AM ()

You can return HTML fragments by wrapping them in Content.Page:

1
2
3
4
5
Content.Page(
    div [
        ...
    ]
)
By on 10/13/2017 2:13 PM ()

Files are served, for security reasons, from your web root folder:

1
Content.File("Main.html")

You can serve files from other folders too:

1
Content.File(@"c:\Main.html", AllowOutsideRootFolder=true)

Files by default are returned as text/html content. You can change the content type by supplying a new one:

1
Content.File("countries.json", ContentType="application/json")
By on 10/13/2017 1:00 PM ()
1
Content.Text("Time now is " + System.DateTime.Now.ToShortTimeString())
By on 10/13/2017 11:05 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper