MVVM for web development

I read on MVVM and still found this very interesting. However, most of the examples I found relate to Windows applications, not web applications. I also saw a lot of mention of the MVVM used with Silverlight, and I know that Silverlight can be used for both web applications and Windows.

So my question is: is MVVM a valid web application template? If so, should the Silverlight user interface? I am in the process of deciding which technologies to use for the new medium-sized website that we need to develop, and Silverlight can be a tough sale to the authorities, which will, although what we use behind the scenes doesn't matter so much .

Any information that anyone can provide when using MVVM in a web environment will be appreciated. Sample code would also be great.

+7
silverlight mvvm jsrender
source share
10 answers

DotVVM is an open source ASP.NET MVVM based on Knockout JS. It is easy to use and you do not need to write a bunch of Javascript code. For most scenarios, you only need C # and HTML with CSS.

The view looks like this: this is HTML extended with server 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> 

Viewmodel is a C # class that looks like this:

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

There is also a Visual Studio Extension that adds IntelliSense and project templates.

The structure handles validation, localization, SPA, and other commonly used functions. It supports both the .NET Framework and the .NET Core.

+12
source share

Of course, MVVM is a valid web template, but it currently has very limited use.

The main difference between MVC and MVVM is updating your application data. For real-time web applications, MVC is preferable because the web is basically one-way communication and all user input is encapsulated by forms.

MVVM is useful in creating truly interactive applications with a rich interface.

So, to make it simple. If you are building a web solution using ASP.NET (or any other server-oriented type), use MVC. If you use a rich user interface application, use MVVM, and if you don't like Silverlight, try KnockoutJS for a Javascript solution.

+6
source share

MVVM can work well on the Internet and in XAML-based technology. XAML tech has the edge in its amazing baked functions that are baked. But with JavaScript libraries such as Knockout (which is great) and JsViews / JsRender (which you should see as soon as JsViews becomes beta).

To answer you specifically: yes, you can do MVVM using web applications. It's good? Yes, if you use a library like Knockout (http://knockoutjs.com). The key to MVVM is that it is a simple partitioning template that:

  • shares view (page)
  • separates the model (source data)
  • shared viewmodel (presentation logic)

Nowhere is the technology prescribed by MVVM. View is your html, your structure. The model is your data (possibly JSON). Viewmodel is your javascript object that separates the logic of your particular view.

A knockout provides a means to bind data to money through a concept that he calls observable. basically think of it as the INotifyPropertyChanged interface, but for JavaScript. Knockout also supports an observable array (which is similar to an ObservableCollection in XAML). The knockout has many other features that allow you to subscribe to data change events, create behavior, customize bindings and much more. Anyway ... with Knockout you get quite a bit.

If you choose MVVM without a library such as Knockout, you can still do it, but you will lose the data binding functions and probably want to write something yourself. But I highly recommend sticking with a library that does this for you.

The long answer ... but I wanted to give you enough to start studying.

+5
source share

For a website (html), it is not very useful, since the mvvm point must have an interface that immediately reflects the changes in the view mode. (through data / event binding).

For the Internet, a change in the viewmodel is usually a post + full screen rebuild.
So why bother ..

However, if you have an AJAX website with one fixed HTML page, if the content is constantly updated using javascript. Then it becomes interesting.

+4
source share

MVVM is essentially an MVC template with specific changes to support application development using the Windows Presentation Foundation.

Model - View - ViewModel
Model - View - Controller

Thus, ViewModel is the controller in MVVM. The template is very good; this makes it easy to create applications that are simple but powerful and easy to check and maintain.

If you want to use MVVM in a web application that is not Silverlight, check out ASP.NET MVC . MVVM is also an option if you use Silverlight. You can even mix the two by hosting the Silverlight app on the MVC website.

+3
source share

MVVM is fully suitable for web development. In fact, it is recommended for Silverlight development. Our company uses MVVM + Silverlight for many of our projects with great success. The initial learning curve can be tough, but as soon as it clicks, it gives many advantages.

In my opinion, for MVVM to really work, you need an infrastructure that has the right to bind. Otherwise, you will need to write a lot of glue code to join your model of viewing and viewing. Silverlight has excellent support for binding, and if everything is done correctly, you can eliminate most of the code in your view, so all your business logic remains in your ViewModel.

Tim Heyer has great tutorials and videos on MVVM with Silverlight. I highly recommend going through his stuff. http://timheuer.com/blog/articles/getting-started-with-silverlight-development.aspx

+2
source share

For web development, I would rather go for MVC. If its pure Silveright, then MVVM can be considered

+1
source share

I have an MVVM implementation for the Internet using various technologies, Knockout, jQuery, Websockets and .NET. Check out the article here: http://salmanq.com/blog/using-the-mvvm-pattern-on-web-applications-part-i/2013/02/

+1
source share

MVVM is fully acceptable with WPF as well as with Silverlight. If you want to use MVVM for web development, you will have to write a lot of jscript code. MSDN has an example on how to do this:

Check out the link below: http://msdn.microsoft.com/en-us/scriptjunkie/hh297451

0
source share

As already mentioned, Knockout.js is a fantastic library that provides many of the features required for MVVM on the web. I created a composite structure, which is a much more complete MVVM structure. It has similarities with Microsoft Prism and is used in a rather large and complex product oriented to web and mobile platforms.

Check it out: http://danderson00.blogspot.com/2012/08/introducing-knockoutcomposite.html

0
source share

All Articles