ASP. NET MVC Learning Note-2. Controller

Source: Internet
Author: User

In MVC, a controller responds to a request to an ASP. NET MVC site, and each browser request is mapped to a specific controller instance. The controller may do the following for a request: return a specific view to the browser or redirect the request to another controller.

The controller is essentially a class that derives from the controller (System.Web.Mvc.Controller base class).

A public method on a controller called Controlleraction,controlleraction cannot be overloaded and cannot be a static method.

The return value of Controlleraction is called ActionResult, which is the content information that the controller returns in response to a browser request. At present, its types mainly include:

☆viewresult

HTML and Tags (common)

Emptyresult

Any results

Redirectresult

Redirect to new URL

Jsonresult

JavaScript object representation results in AJAX requests

Javascriptresult

JavaScript scripts

Contentresult

Plain Text Results

Filecontentresult

Downloadable files (using binary content)

Filepathresult

The path to the downloadable file

Filestreamresult

Downloadable files (using file streams)

In general, the program does not directly return ActionResult, but instead calls the Controller base class method to return,

View ()

View, return Viewresult

Redirect ()

Redirect, return Redirectresult

Redirecttoaction ()

Back to Redirecttorouteresult

Redirecttoroute ()

Back to Redirecttorouteresult

Json ()

Back to Jsonresult

Javascriptresult ()

Back to Javascriptresult

Content ()

Back to Contentresult

File ()

Returns Filecontentresult, Filepathresult, or Filestreamresult

ASP. NET MVC Learning Note-2. Controller

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.