Share the ASP. NET Learning Note (6) Webpages form

Source: Internet
Author: User
forms are parts of an HTML document that place input controls (text boxes, check boxes, radio buttons, drop-down lists).

Create an HTML input page

Razor instances


Razor Instance-Display image

Suppose you have 3 images in your image folder, and you want to display the images dynamically based on the user's choice.

This can be achieved through a simple Razor code.

If you have an image in your site's image folder named "Photo1.jpg", you can use the element of HTML to display the image as follows:

The following example shows how to display the image that the user selects from the following list:

Razor instances

@{var imagepath= ""; if (request["Choice"]! = null) {imagepath= "images/" + request["Choice"];} <! DOCTYPE html> 

Example explanation

The server created a variable called ImagePath.

The HTML page has a drop-down list (<select> element) named Choice. It allows the user to choose a name, such as Photo 1, according to their wishes, and when the page is submitted to the WEB server, a file name (such as Photo1.jpg) is passed.

The Razor code reads the value of Choice by request["Choice". If the image path (images/photo1.jpg) built by code is valid, the image path is assigned to the variable ImagePath.

The, element is used to display an image in an HTML page. The SRC attribute is used to set the value of the ImagePath variable when the page is displayed.

The element is in an if block, which is designed to prevent the display of images without names, such as when the page is loaded for the first time.

"Recommended"

1. ASP. NET free Video Tutorials

2. Share the ASP. NET Learning Notes (1)--webpages Razor

3. Share the ASP. NET Learning Notes (2)--webpages Introduction

4. Share the ASP. NET Learning Notes (3) Webpages layout

5. Share the ASP. NET Learning Notes (4) folder

6. Share the ASP. NET Learning Notes (5) global page AppStart and Pagestart

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.