如何在视图(MVC3)中处理WCF的JSON输出
我有一个场景,WCF 将以下数据(在下面给出的函数中)返回到 VIEW。
private List<KeyDatesCalendar> GetKeyDatesCalendarData()
{
//Dummy Data for BrandsCalendar CheckList
var keyDatesCalendar = new List<KeyDatesCalendar>()
{
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 02, 09),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 05),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 06),
EventType = 4
},
};
视图中数据的处理是通过以下代码完成的:
initCalendars({
from : '02/01/2011',
to : '01/31/2013',
dates : [
@for(int i=0, [email protected]; i<l; i++)
{
@Html.Raw("['" + @Model.KeyDatesCalendar[i].EventDate.ToString("yyyy/MM/dd") + "'," + @Model.KeyDatesCalendar[i].EventType + ",'" + @Model.KeyDatesCalendar[i].EventText + "']" + (i < (l-1) ? "," : ""));
}
]
});
我如何接收 JSON 输出并在视图中处理相同的值,而不是 WCF 方法中的硬编码值。
我是这里的初学者,感谢您的详细解答。
谢谢, 阿达什
I have a scenario where the WCF returns the follwing data ( in the function given below) to a VIEW.
private List<KeyDatesCalendar> GetKeyDatesCalendarData()
{
//Dummy Data for BrandsCalendar CheckList
var keyDatesCalendar = new List<KeyDatesCalendar>()
{
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 02, 09),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 05),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 06),
EventType = 4
},
};
The processing of the data in view is done by the following code:
initCalendars({
from : '02/01/2011',
to : '01/31/2013',
dates : [
@for(int i=0, [email protected]; i<l; i++)
{
@Html.Raw("['" + @Model.KeyDatesCalendar[i].EventDate.ToString("yyyy/MM/dd") + "'," + @Model.KeyDatesCalendar[i].EventType + ",'" + @Model.KeyDatesCalendar[i].EventText + "']" + (i < (l-1) ? "," : ""));
}
]
});
Instead of the hardcoded values in WCF method, how Do i recieve a JSON output and process the same in View.
I am a beginner here, appreciate your detail answers.
Thanks,
Adarsh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意之前的许多评论,如果您使用 ASP.NET MVC,您不妨从那里进行 JSON 转换(看看 JsonResult 类)。但是,如果您确实希望 WCF 服务以 JSON 格式返回结果,请参阅此博客文章我前一段时间写的可能有帮助。
伊恩
I would agree with many of the previous comments, if you're using ASP.NET MVC you might as well do the JSON conversion from there (have a look at JsonResult class). However, if you really want the WCF service to return the result in JSON format, this blog post I wrote a while back might help.
Iain