ASP.NET Web Pages – HTML 表單

ASP.NET Web Pages – HTML 表單

ASP.NET Web Pages – HTML 表單


資料來源: https://www.runoob.com/aspnet/webpages-forms.html


Code01.

<html>
    <body>
        @{
            if (IsPost)
            {
                string companyname = Request["companyname"];
                string contactname = Request["contactname"];
                <p>You entered: <br />
                Company Name: @companyname <br />
                Contact Name: @contactname </p>
            }
            else
            {
                <form method="post" action="">
                    Company Name:<br />
                    <input type="text" name="CompanyName" value="" /><br />
                    Contact Name:<br />
                    <input type="text" name="ContactName" value="" /><br /><br />
                    <input type="submit" value="Submit" class="submit" />
                </form>
            }
        }
    </body>
</html>


Code02.

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

<!DOCTYPE html>
<html>
    <body>
        <h1>Display Images</h1>
        <form method="post" action="">
            I want to see:
            <select name="Choice">
            <option value="Photo1.jpg">Photo 1</option>
            <option value="Photo2.jpg">Photo 2</option>
            <option value="Photo3.jpg">Photo 3</option>
            </select>
            <input type="submit" value="Submit" />
            @if (imagePath != "")
            {
                <p>
                <img src="@imagePath" alt="Sample" />
                </p>
            }
        </form>
    </body>
</html>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *