Tutorial on handling return values ​​in .NET MyMVC framework

Y2J
Release: 2017-05-17 11:26:19
Original
2092 people have browsed it

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);}
Copy after login

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
Copy after login

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());
Copy after login

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

2. ASP free video tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template