Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of MyMVC Framework processing return value in .NET

Shulou Source: shulou.com Published: 2022-06-03 12:37:15 09月12日 Update

This article mainly introduces the sample analysis of the return value of the MyMVC Framework in .NET, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

The time when the MyMVC framework handles the return value is in the ExecuteAction method (the code above).

Here is only a simple supplementary note.

I defined an interface for the result of Action:

Public interface IActionResult {void Ouput (HttpContext context);}

Four kinds of ActionResult are implemented in the framework:

/ indicates a result of a user control (the user control will be executed by the frame) / public sealed class UcResult: IActionResult/// indicates a redirected result / public sealed class RedirectResult: IActionResult/// a Json object result / public sealed class JsonResult: IActionResult/// indicates a page result (the page will be executed by the frame) / public sealed class PageResult: IActionResult

To output the return value, not only did I use the IActionResult interface, but I also used the following call:

Context.Response.Write (result.ToString ())

Don't underestimate the call to ToString ().

For custom data types, you can use it to control whether the final output to the client is JSON or XML, or your own-defined text serialization format (for example, splicing of special delimiters), so it has enough power to replace the JsonResult type without affecting the unit testing of Action.

The powerful reason for ToString () is that it is a virtual method that can be overridden by derived classes.

So, if you plan to return only one data entity object to the client, you can either implement the IActionResult interface or override the ToString method.

Thank you for reading this article carefully. I hope the article "sample Analysis of MyMVC Framework processing return values in .NET" shared by the editor will be helpful to you. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Frames results articles processes interfaces methods examples analysis customers objects controls data users types pages output powerful special code value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Shulou Tech Info Docker Xiaomi