通过MVC控制器/ ajax调用web api控制器 [英] Calling web api controller through MVC controller / ajax

查看:147
本文介绍了通过MVC控制器/ ajax调用web api控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



以下网络API呼叫有什么区别。



1。通过MVC控制器进行web api调用以从数据库获取数据。

ClientScript - > MVC控制器方法 - > Web Api控制器。

它分别返回数据并将在页面中呈现。



2.通过Ajax.request进行web api调用从数据库中获取数据。

ClientScript - > Web Api控制器

它返回数据并将在页面中呈现。



哪一个在性能方面表现不错。



谢谢。



我尝试了什么:



我用Google搜索,但无法得到明确答案。

Hi everyone,

what is the difference for below web api calls.

1. Make a web api call through MVC controller to get the data from database.
ClientScript -> MVC controller method -> Web Api controller.
It returns data respectively and will be render in page.

2. Make a web api call through Ajax.request to get the data from database.
ClientScript -> Web Api controller
It returns data and will be render in page.

Which one is good in terms of performance basis.

Thanks.

What I have tried:

I have googled ,but couldn't get clear answer.

推荐答案

所以我认为你正在做的是从mvc控制器调用web api操作vrs直接调用客户端到web api。



首先要注意的是,web api和mvc基本上是一回事。在.net核心中它们共享相同的基类。



在性能方面,因为它们基本相同,根据您声明的流程,你是可能会想要直接拨打你的网络api端点vrs你的mvc端点调用你的web api ... soley,因为你没有再发出第二个请求。



如果我没有正确理解你并以同样的方式调用MVC和Web API(只有javascript)......那么性能很可能是相同的。



但实际上,您应该采取类似提琴手的方式,监控您的流量,看看哪种方式最适合您。
So what i think you are doing is calling a web api action from an mvc controller vrs a direct call client side to web api.

First thing to note, web api and mvc are basically the same thing. So much so that in .net core they share the same base class.

In terms of performance, since they are essentially the same, based on your stated process you are probably going to want to make calls directly to your web api end point vrs your mvc endpoint that calls your web api...soley for the reason that you don't make a second request.

If i did not understand you correctly and you call MVC and Web API in the same manner (only javascript)...then performance is more than likely the same.

But really, you should just take something like fiddler, monitor your traffic and see what works best for you.


这篇关于通过MVC控制器/ ajax调用web api控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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