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