The time when the MyMVC framework processes the return value is in the ExecuteAction method (there is that code in front).
Here is just a simple additional explanation.
I defined an interface for the result of Action:
public interface IActionResult{ void Ouput(HttpContext context);}
Four types of ActionResult are implemented in the framework:
/// <summary> /// 表示一个用户控件结果(用户控件将由框架执行)/// </summary>public sealed class UcResult : IActionResult/// <summary> /// 表示一个重定向的结果/// </summary>public sealed class RedirectResult : IActionResult/// <summary> /// 一个Json对象结果/// </summary>public sealed class JsonResult : IActionResult/// <summary> /// 表示一个页面结果(页面将由框架执行)/// </summary>public sealed class PageResult : IActionResult
When you want to output the return value, not only use With the IActionResult interface, I also use the following call:
context.Response.Write(result.ToString());
Don’t underestimate the ToString() call.
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: spliced together with special delimiters), therefore, it has enough ability to replace the JsonResult type, and it also does not affect the unit test of Action.
The power of ToString() is that it is a virtual method and can be overridden by derived classes.
So, if you only plan to return a data entity object to the client, you can either implement the IActionResult interface or override the ToString method.
【Related Recommendations】
1. Special Recommendation: "php Programmer Toolbox" V0.1 version download
3. Entry-level .NET MVC example
4. MyMVC frame’s detailed explanation of the process of finding Action
5. .NET MyMVC frame’s detailed explanation of the process of executing Action
6. .NET MyMVC framework tutorial on how to assign values to methods
The above is the detailed content of Tutorial on handling return values in .NET MyMVC framework. For more information, please follow other related articles on the PHP Chinese website!