asp.net MVC framework (Part III): uploading ViewData from controller to view

Source: Internet
Author: User
Tags http request

The ASP.net MVC framework is an optional method that you can use to structure your asp.net Web application, so that it has a clear separation of concerns, facilitates your unit test code and supports the TDD process.

I'll talk about how the controller interacts with the view, specifically, I'll discuss the various ways you can upload data from the controller to the view to show the replies returned to the client.

A brief summary of the first part

In the first part of this series, we created an E-commerce site that implements a basic product list/browsing support. We implemented this site with the ASP.net MVC framework, which naturally turns code into a unique controller, model, and view component.

When the browser sends an HTTP request to our web site, the asp.net MVC framework uses its URL path selection engine to map incoming requests to an action method on a controller to handle it. In an MVC based application The controller is responsible for processing incoming requests, processing user input and interactions, and executing the application logic based on these inputs and interactions (getting or updating model data stored in the database, and so on).

When the build returns to the client's HTML reply, the controller is typically working with the view component, which is implemented as a separate class or template that is independent of the controller, and is designed to focus exclusively on encapsulating the display logic.

The view should not contain any application logic or database access code, and all application/data logic should be handled by the Controller class. The motivation for this division is to help force a clear separation between your application/data logic and the interface Generation code. It also facilitates your unit testing your application/data logic independently of your interface display logic.

The view should use only the view-specific data that is passed from the controller to generate the output. In the ASP.net MVC framework, we call this view-specific data "ViewData". The rest of this blog will discuss some of the different ways you can use to pass ViewData from a controller to a view to generate a display.

A simple product list scenario

To help illustrate some of the techniques we can use to pass ViewData from the controller to the view, let's build a simple product List page:

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.