ASP. NET Web Pages-HTML form, asp. netpages

Source: Internet
Author: User

ASP. NET Web Pages-HTML form, asp. netpages

A form is the position where you place input controls (text boxes, check boxes, single quotes, and drop-down menus) in HTML documents.

Create a Razor instance on the HTML input page

Running instances



Razor instance-display image

Suppose there are three images in your image folder, and you want to dynamically display these images based on your choice.

A short section of Razor can be easily implemented.

If the image name in the website image folder is "Photo1.jpg", you can use the HTML element to display the image, as shown in the following figure:


The following example shows how to display the images selected from the drop-down list:

Razor instance
@{var imagePath=""; if (Request["Choice"] != null)   {imagePath="images/" + Request["Choice"];} } <!DOCTYPE html> 

Running instances

Example

Create a server namedImagePath.

The HTML page has the nameChoiceOfDrop-down list(<Select> element ). It allows users to select a friendly (Editor's note: easy to read) name (for examplePhoto 1When the page is submitted to the web server, the file name (for example, Photo1.jpg) is passed to the server ).

RazorRequest ["Choice"]Read the Choice value. If the value exists, the Code constructs the path pointing to the image (images/Photo1.jpg) and stores the path in the VariableImagePath.

The element on the HTML page displays the image. When the page is displayed, the src attribute is set to the value of the imagePath variable.

If the value of the imagePath variable is null, the element cannot display images that do not exist (for example, when the page is loaded for the first time ).

 

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.