天天看点

MVC应用程序使用Web Services(asmx)

这次,我们练习MVC应用程序中,应用web service。

先在MVC应用程序中创建一个目录Services,将用来存储Service.asmx。

MVC应用程序使用Web Services(asmx)

在Controllers目录下创建一个ExerciseController.cs和一个视图ActionResult:

MVC应用程序使用Web Services(asmx)

在MVC5创建好Controller之后,自动会在Views目录下面创建好相关的视图目录:

MVC应用程序使用Web Services(asmx)

创建视图:

MVC应用程序使用Web Services(asmx)

在#3步,我们写jquery代码,获得Web Server返回的数据:

MVC应用程序使用Web Services(asmx)

实时演示:

MVC应用程序使用Web Services(asmx)

以下内容于2014-03-14 16:30分补充。

两个Click的事件处理逻辑一样的,可以重构为一个扩展方法:

MVC应用程序使用Web Services(asmx)

继续阅读