MVC 4网页API返回的行动:类型VS Htt的presponseMessage [英] MVC 4 Web API Action return: Types vs HttpResponseMessage

查看:115
本文介绍了MVC 4网页API返回的行动:类型VS Htt的presponseMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么类型的返回区别例如

What is the difference returning Types e.g.

    public class MyController : ApiController
    {
        public IEnumerable<MyType> Get()...

VS

返回的Htt presponseMessage:

Returning HttpResponseMessage:

    public class MyController : ApiController
    {
        public HttpResponseMessage Get()...

...

是否MVC封装类型为Htt的presponseMessage内容对象反正?页面上的结果看起来时明确添加格式化,除了相同的。

Does MVC wraps types into HttpResponseMessage content object anyways? The result on the page looks the same besides when formatters are explicitly added.

的区别是什么给客户?

推荐答案

有什么区别。

如果您返回CLR类型,它将与的Htt presponseMessage 包裹反正。

If you return CLR type, it will be wrapped with HttpResponseMessage anyway.

唯一的区别是,如果返回的Htt presponseMessage 你有机会直接与HTTP工作 - 所以你可以设置标题,旁路 MediaTypeFormatters 等。

The only difference is that if you return HttpResponseMessage you get a chance to work directly with HTTP - so you can set headers, bypass MediaTypeFormatters and so on.

这是个人的preference和/或在你的行动进行的活动的所有问题。

It's all a matter of personal preference and/or the activity that's performed in your action.

这篇关于MVC 4网页API返回的行动:类型VS Htt的presponseMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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