如何从Web API返回MVC视图 [英] How to return MVC View from web API

查看:595
本文介绍了如何从Web API返回MVC视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我已经在vs 2013中创建了一个Web API(它运行良好),我的目标是将MVC View返回给客户端例如:

调用url:www.xxx.com/api/home/应返回简单的mvc视图,我的模型将从web api更新。



请建议



谢谢!

Yaniv

Hello All,

I already create a Web API in vs 2013 (and it working good), my goals is to return also MVC View to the client for example:
call to url: www.xxx.com/api/home/ should return simple mvc view, my model will update from the web api.

Please advice

Thanks!
Yaniv

推荐答案

你没有。



你可以退回其中一个,而不是两个。





坦率地说,WebAPI控制器只返回数据,而不是视图页面。 MVC控制器返回视图页面。



是的,你的MVC代码可以是WebAPI的消费者,但不是相反。
You don't.

You can return one or the other, not both.


Frankly, a WebAPI controller returns nothing but data, never a view page. A MVC controller returns view pages.

Yes, your MVC code can be a consumer of a WebAPI, but not the other way around.


这篇关于如何从Web API返回MVC视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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