用于Web开发的MVVM [英] MVVM for Web Development

查看:64
本文介绍了用于Web开发的MVVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读MVVM,到目前为止发现它非常有趣.但是,我发现的大多数示例都是针对Windows应用程序的,而不是针对Web应用程序的.我也看到了很多与Silverlight一起使用的MVVM的提及,而且我知道Silverlight可用于Web或Windows应用程序.

I've been reading up on MVVM and so far have found it very interesting. Most of the examples I've found, however, are for Windows apps, as opposed to Web apps. I've also seen a lot of mention of MVVM used with Silverlight, and I know Silverlight can be used for either Web or Windows apps.

所以我的问题是-MVVM是基于Web的应用程序的有效模式吗?如果是,则UI是否必须为Silverlight?我正在决定要为新的中型网站使用哪些技术,我们需要设计,而Silverlight可能很难被强权推销,尽管我们在后台使用的技术无关紧要非常.

So my question is - is MVVM a valid pattern for Web-based apps? If it is, does the UI have to be Silverlight? I'm in the process of deciding which technologies to use for a new mid-size website we need to design, and Silverlight may be a hard sell to the powers-that-be, though what we use behind the scenes doesn't matter so much.

任何人都可以提供在Web环境中使用MVVM的信息,将不胜感激.示例代码也很好.

Any info anyone can supply on using MVVM in a web environment would be appreciated. Example code would be great as well.

推荐答案

DotVVM 是一种开源ASP.基于Knockout JS的基于NET的MVVM框架.它使用简单,您无需编写大量的Javascript代码.在大多数情况下,您只需要C#和带有CSS的HTML.

DotVVM is an open source ASP.NET-based MVVM framework based on Knockout JS. It's simple to use and you don't have to write tons of Javascript code. For most scenarios, you need just C# and HTML with CSS.

视图看起来像这样-它是HTML扩展,带有服务器控件和数据绑定:

The view looks like this - it is a 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是一个C#类,它看起来像这样:

The viewmodel is a C# class which looks like this:

public class ContactFormViewModel 
{
    public string Name { get; set; }
    public string Email { get; set; }

    public void Submit() 
    {
        ContactService.Submit(Name, Email);
    }
}

还有 Visual Studio扩展,它添加了IntelliSense和项目模板.

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

该框架处理验证,本地化,SPA和其他常用功能.它同时支持.NET Framework和.NET Core.

The framework handles validation, localization, SPAs and other frequently used features. It supports both .NET Framework and .NET Core.

这篇关于用于Web开发的MVVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆