多语言展示
当前在线:180今日阅读:2今日分享:38

asp.net mvc编写跨域调用WEBAPI传递JSON数据

在asp.net mvc中如何写webAPI及调用说明(简单版),实现跨域调用WEBAPI返回JSON数据。
工具/原料
1

vs2013,

2

笔记本

方法/步骤
1

编写实体类       public class KnowledgeLecture    {        public string id;        public string title;        public string lectureContent;        public string organize;        public string participant;        public DateTime? lecturetime;        public DateTime? creatorTime;    }

2

编写webapi 代码,可以发布出去,方便其他系统调用: //

  //获取所有的应急知识讲座 //        //id、讲座标题、创建时间等的json数据 [HttpGet] public IEnumerable GetAllKnowledgeLectureInfo() {DateTime time = DateTime.Now.ToString('yyyy-MM-dd').ToDate();var data = (from s in db.FXJC_yjzh_training_knowledgeLecture.Where(s => s.deleteMark != true) select s);List Result = new List(); foreach (var o in data)     {         Result.Add(new KnowledgeLecture()            {                    id = o.id,                    title = o.lectureTitle,                    lectureContent=o.lectureContent,                    organize=o.Sys_Organize.F_FullName,                    participant=o.participant,                    lecturetime=o.lecturetime,                    creatorTime = o.creatorTime,                });            }            return Result.OrderByDescending(s => s.creatorTime);        }

3

新的应用系统需要调用上面的接口,编写新的业务前端代码

注意事项
1

以上就是小编带给大家的如何操作的关键所在,如果觉得本经验对你们有帮助,请给小编我进行一点小小的支持。大家也可以下面发表一下自己的看法。

2

个人意见,仅供参考。

推荐信息