简体   繁体   English

如何在MVC5(Ajax / jQuery)中动态更新模型

[英]How to update the model dynamically in MVC5 (Ajax / jQuery)

I have a simple ASP.net MVC5 website with Code-first EF. 我有一个带有Code-first EF的简单ASP.net MVC5网站。 I would like to learn how to automatically update/refresh the view-models so that the user sees updated information. 我想学习如何自动更新/刷新视图模型,以便用户看到更新的信息。

The website is a simple auction site and I would like the current bid amount to automatically refresh in a user's view. 该网站是一个简单的拍卖网站,我希望当前的出价金额能够在用户视图中自动刷新。 The refreshing could be either server-pushed or client-polled; 刷新可以是服务器推送的,也可以是客户端轮询的。 I don't mind which. 我不在乎。

My current understanding is that this can be achieved using an Ajax toolkit or using jQuery. 我目前的理解是,可以使用Ajax工具箱或jQuery来实现。 But I have not used these technologies before and docs/tutorials for this scenario seem to be lacking. 但是我之前没有使用过这些技术,因此似乎缺少针对这种情况的文档/教程。 I would very much appreciate a couple of pointers as to where I can start reading relevant material about the options and how to go about this seemingly simple task. 我将非常感谢您在哪里可以开始阅读有关这些选项的相关材料以及如何执行此看似简单的任务的一些指示。

A short code sample would also be of great benefit. 简短的代码示例也将带来巨大的好处。

For a client-polled solution, you can use MVC "Partial views" and jQuery. 对于客户端轮询的解决方案,可以使用MVC“部分视图”和jQuery。

A quick guide to get started is here: http://www.yodotnet.com/post/2012/02/12/MVC-Makes-AJAX-easier.aspx . 快速入门指南在这里: http : //www.yodotnet.com/post/2012/02/12/MVC-Makes-AJAX-easier.aspx

More about partial views here: http://www.mikesdotnetting.com/Article/105/ASP.NET-MVC-Partial-Views-and-Strongly-Typed-Custom-ViewModels . 有关部分视图的更多信息,请访问: http : //www.mikesdotnetting.com/Article/105/ASP.NET-MVC-Partial-Views-and-Strongly-Typed-Custom-ViewModels

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM