我应该使用带有jquery或razor语法的web api [英] Should I use web api with jquery or razor syntax

查看:113
本文介绍了我应该使用带有jquery或razor语法的web api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!所以标题几乎说明了一切。我正在创建ASP.NET(MVC)应用程序,我想知道我应该在哪里使用web api + jQuery以及应该在哪里使用razor语法。我个人认为,当没有机会创建客户端(桌面,xamarin应用程序)并且应用程序不大(所以你不需要从服务器节省资源)时,没有理由创建一个web api ..你应该使用razor语法......但这是真的吗?我问这个是因为我听说有些人说使用剃须刀是不好的编码习惯。这是真的吗?



我的尝试:



没什么写在这里。是一个编程问题。

解决方案

你将苹果与橙子进行比较。



Razor是一种混合语法HTML和C#或VB.NET用于为浏览器客户端生成HTML页面。



Web API不返回HTML,而是以JSON或XML格式化数据。 br />


那么,你在这个网站做什么?什么是目标客户端?



您甚至可以同时执行这两项操作,WebAPI为远程客户端和您的网站提供服务,其中代码隐藏调用Web API你建立。


Hello ! So the title pretty much says it all. I am creating ASP.NET(MVC) apps, and i am wondering where should i use web api + jQuery and where should use razor syntax. I personally think that when there is not a chance of creating an client(desktop, xamarin app) and the app is not big(so you don't necessary want to "save resources" from the server) there is not a reason of creating a web api .. and you should use razor syntax .... but is that true ? I am asking this because i 've heard some guys saying that using razor is bad coding practice. Is that true ?

What I have tried:

Nothing to write here. Is a programming question.

解决方案

You comparing apples to oranges.

Razor is a hybrid syntax of HTML and either C# or VB.NET used to generate HTML pages for a browser client.

A Web API returns no HTML but data formatted in either JSON or XML.

So, what are you doing with this site? What is the target client?

You could even do both, with the WebAPI servicing both remote clients AND your website, where the code-behind makes calls to the Web API you build.


这篇关于我应该使用带有jquery或razor语法的web api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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