Code Monkey home page Code Monkey logo

dotvvm's Introduction

DotVVM = HTML + C#

.NET-based MVVM Framework for Web Apps

license Join the chat at https://gitter.im/riganti/dotvvm

TFS Build:

DotVVM is an ASP.NET framework that lets you build line-of-business applications and SPAs without writing tons of JavaScript code. You only have to write a viewmodel in C# and a view in HTML. DotVVM will do the rest for you.

DotVVM brings full MVVM experience and it uses KnockoutJS on the client side. It handles the client-server communication, validation, date & time formatting on the client side, SPAs and much more.

It is open source, it supports both OWIN and ASP.NET Core and it runs on .NET Framework, .NET Core and Mono.

It also offers a free extension for Visual Studio 2015 and 2017 with IntelliSense and other useful features which make the development really easy and productive.

Info: DotVVM for Visual Studio PRO v1.1.90.0 is compatible with Visual Studio 2017 v15.6 and newer.

How To Use

The Views in DotVVM use HTML syntax with controls and data-bindings.

<div class="form-control">
  <dot:TextBox Text="{value: Name}" />
</div>
<div class="form-control">
  <dot:TextBox Text="{value: Email}" />
</div>
<div class="button-bar">
  <dot:Button Text="Submit" Click="{command: Submit()}" />
</div>

The ViewModels are plain C# objects. You can call public methods from the View.

public class ContactFormViewModel
{
  public string Name { get; set; }
  public string Email { get; set; }
  public void Submit()
  {
    ContactService.Submit(Name, Email);
  }
}

You just need to know C#, HTML and CSS. For most scenarios you don't have to write any JavaScript code. If you are wondering what is going on, see the "How Does it Work" section below.


Features of DotVVM (Open Source & Free for Everyone)


Need More? We have Commercial Controls!


How to Start

  1. Install the DotVVM for Visual Studio extension.

  2. Read the documentation.

How Does it Work

DotVVM is no magic, so let's have a look at how it works. Or at least how would a simplified core work.

Page Load

When the page is requested, DotVVM will process the dothtml markup into a control tree - a tree made of DotvvmControl instances which correspond to the structure of dothtml. In the meantime, your ViewModel is initialized so data bindings can be evaluated on the server. Then, the page is "rendered" to HTML with knockout data-bindings - each DotvvmControl handles the rendering of its properties and can decide if the data bindings should be evaluated on the server or translated to a Javascript expression (or both). The ViewModel is serialized to JSON and included in the page.

On the client side, after the page is loaded the ViewModel is deserialized and used as a knockout model. When you touch the page (edit a textbox or so) the changes are assigned back to the knockout model - it always represents the page's current state.

Command bindings

We have two types of commands in DotVVM - the powerful and expansive command and its lighter counterpart staticCommand.

When a command is invoked a "postback" is dispatched - the entire ViewModel is serialized and sent to the server. Here, the page is created again, ViewModel is deserialized, the expression in the binding is invoked, the ViewModel is serialized and sent back to the client. Note that you can control which parts of the ViewModel are sent using the Bind attribute.

A staticCommand is slightly different as the binding expression is not invoked on the server but instead is translated to Javascript and invoked client-side. Only when you use a function that is not translatable to JS and is marked with an AllowStaticCommand attribute the request to the server is dispatched. However, it is not the full postback - it will only contain the function's arguments. On the server, the function is going to be invoked (with the deserialized args) and only its result will be sent back to the client. When the response returns, the rest of the expression will be evaluated. If you'd have a look at the JS generated from your staticCommand, you would find an ugly expression that invokes some function on the server and processes the results in the callback.


More Info

dotvvm's People

Contributors

adamjez avatar adamkopriva22 avatar cafour avatar darilek avatar djanosik avatar exyi avatar holajan avatar jaroslavholcman avatar jechtom avatar jozefpastucha avatar juratime avatar kiraacorsac avatar leeemons avatar macakm avatar martindybal avatar michaltichy avatar mrnustik avatar mylan719 avatar padresvk avatar parmap avatar pavelpolasek avatar ppech avatar quigamdev avatar ridercz avatar rigantiteamcity avatar ropack avatar rumbeer avatar sejsel avatar tomasherceg avatar tomasjurasek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.