WebSharper documentation
C# Support

UI Samples in C#

These samples demonstrate how to use WebSharper.UI to build reactive web applications in C#. You can compare them with the F# equivalents.

Reactive variables

Differences from F#:

  • View.Map2 is available as an extension method instead of a static method.
  • Vars and Views can be embedded as content directly in HTML combinators like div
  • button has a simplified overload that accepts the text and action directly.

Shorthand Views with .V

  • Lensing on C# records is supported, so input(state.V.Name) creates an input element with two-way immutable binding to the Name property of the state record.
  • Instead of a V function, the V.V helper is used to create reactive expressions.

HTML templates

  • The C# version sets ClientLoad = FromDocument in a HTML comment, for the templating code generator to use.
  • The ListModel type requires a key for each element, so we use a C# tuple with named elements.
  • C# template holes do not automatically support the .V shorthand, so the V.V helper is used.

Client-side routing

  • The endpoints must be declared as a base class, and subclasses that are nested inside it. This enables Router.Infer to work.
  • Fullly qualified names are used for the Router and Doc types for disambiguation. This is intended to be improved in the future. See the issue.

On this page