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 ).