简体   繁体   English

我应该如何在Web API控制器方法中返回数据?

[英]How should i return data in Web API Controller Methods?

I have a UI that needs lots of information. 我的UI需要大量信息。 Most of the information has been identified as separate entities in database. 大多数信息已被标识为数据库中的单独实体。 For example, displaying the details of an Employee. 例如,显示员工的详细信息。 The UI page might be Employee details with various sections regarding Employee Information such as Personal Details, Address, Contact details, Project Details etc. UI页面可能是员工详细信息,其中包含有关员工信息的各个部分,例如个人详细信息,地址,联系方式,项目详细信息等。

So if we derive the entities for the same requirement, we will have following tables 因此,如果我们为相同的要求导出实体,我们将有以下表格

Employee 雇员

Address 地址

Contact 联系

Project 项目

We will be implementing repository pattern in DA layer, and ASP.Net Web API as our restful service layer. 我们将在DA层中实现存储库模式,并将ASP.Net Web API作为我们的静态服务层。

So, now if i need to display Employee details in the UI, what should be the best approach. 因此,现在,如果我需要在UI中显示Employee详细信息,那应该是最好的方法。 What i was thinking is mentioned below. 我在想什么在下面提到。

Approach 途径

There will be a single call to Web Api to get the Employee details. 将只需要致电Web Api即可获取员工详细信息。 Internally it will connect to database multiple times to get Employee details, Address information, Contact information, Projects information etc and populate into one EmployeeDetailsModel (a kind of viewmodel ) and return this as a JSON. 在内部,它将多次连接到数据库以获取Employee详细信息,地址信息,联系信息,项目信息等,并填充到一个EmployeeDetailsModel(一种viewmodel )中,并将其作为JSON返回。

Is this a good approach ? 这是一个好方法吗? If there is any other better approach please suggest 如果还有其他更好的方法,请提出建议

Going with your approach might prove as a poor user experience as users will wait for all the data to be assembled. 采用这种方法可能会导致不良的用户体验,因为用户将等待所有数据组装完毕。 I suggest you divide your web page into sections. 我建议您将网页分成几个部分。 First call employee data, and then on a different client event (say click the employee's project cell) call the employee's project detail (supposing it is another table) 首先调用员工数据,然后在另一个客户事件(例如,单击员工的项目单元格)上调用员工的项目明细(假设它是另一个表)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从web api控制器返回文件? - How to return a file from web api controller? 在 ASP Web API 控制器中创建自定义方法并检索它们的数据 - Create Custom Methods in ASP Web API Controller and retrieve their data 需要帮助调用Web Api控制器方法来检索数据 - Need help calling Web Api controller methods to retrieve data 如何在同一控制器中获得MVC4 Web API以支持HTTP动词和“操作”方法? - How do I get MVC4 Web API to support HTTP Verbs and “Action” methods in the same controller? 如何在Web API2控制器中放置多个GET方法? - How to put multiple GET methods in Web API2 controller? 如何从 ASP.Net Core Web API Controller 中的数据库返回关系数据 - How to return a relational data from DB in ASP.Net Core Web API Controller 我应该返回状态代码还是在.Net Web Api 2中抛出异常 - Should I return a status code or throw an exception in .Net Web Api 2 Controller方法返回ActionResult的原因是什么? (ASP.NET Core Web API) - What's the reason why Controller methods return ActionResult? (ASP.NET Core Web API) Web API控制器中的多种GET和POST方法 - Multiple GET and POST methods in Web API controller Web API控制器无法识别新添加的方法 - Web API Controller is not recognizing newly added methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM