Use ViewBag to transfer data from controller to view, viewbag View

Source: Internet
Author: User

Use ViewBag to transfer data from controller to view, viewbag View

In the http://www.cnblogs.com/insus/p/4308740.html of ASP. net mvc reading XML and displaying ViewData, ViewData is used in the Controller to transmit data to the view. In this article, Insus. NET wants to use ViewBag.

Insus. NET simulates an example to display an image. For example, a project contains several images:

 

Create a model with the following attributes:

 

Create Entity:

 

Create a controller. If the Controller already exists, open it and create an Action. In the Action, store the List <T> data to the highlight part of ViewBag. X.

 

Create View:

 

The Razor syntax in this article is that the Code is directly encapsulated in @ {...}, and the previous article is a line expression (variable and function) that starts.

The image path can be interpreted as @ url. Content.

Demo:

 

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.