从apicontroller传递值以在asp.net mvc4中查看 [英] pass value from apicontroller to view in asp.net mvc4

查看:67
本文介绍了从apicontroller传递值以在asp.net mvc4中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的api控制器中有数据列表.

I have list of data in my api controller.

我想通过类似于viewbag的方式传递此数据以进行查看.

I want to pass this data to view using something similar to viewbag.

我知道我们不能在apicontrller中使用viewbag,所以还有其他选择吗?

I know we cant use viewbag in apicontrller , So Is there any alternative for it.

推荐答案

通常ApiControllers不返回视图.他们为此返回 models HttpResponseMessage .因此,您可以简单地使用一个包含所需属性的视图模型,然后让您的API操作返回该视图模型.

Normally ApiControllers do not return views. They return models, or HttpResponseMessage for that matter. So you could simply have a view model that will contain the required property and then have your API action return this view model.

这篇关于从apicontroller传递值以在asp.net mvc4中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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