Share ASP.NET study notes (6) WebPages form

零下一度
Release: 2017-05-25 09:16:19
Original
1335 people have browsed it

A form is the part of an HTML document where input controls (text boxes, check boxes, radio buttons, drop-down lists) are placed.

Create an HTML input page

RazorExample

  @{ if (IsPost) { string companyname = Request["companyname"]; string contactname = Request["contactname"]; 

You entered:
Company Name: @companyname
Contact Name: @contactname

} else {
Company Name:

Contact Name:


} }
Copy after login

Razor Example - Display Image

Assume that in your There are 3 images in the images folder and you want to display the images dynamically based on the user's selection.

This can be achieved with a simple piece of Razor code.

If you have an image named "Photo1.jpg" in your website's images folder, you can use the HTMLelement to display the image, like this:

Sample
Copy after login

The following example demonstrates how to display an image selected by the user from the following list:

Razor Example

@{var imagePath=""; if (Request["Choice"] != null){imagePath="images/" + Request["Choice"];} }    

Display Images

I want to see: @if (imagePath != ""){

Sample

}
Copy after login

Example Explanation

The server creates a file calledVariableof imagePath.

The HTML page has a drop-down list (