下面的代码演示了Razor模式下一个简单的表单提交代码,当用户提交信息后,会显示用户提交的字段内容,无需后端代码支持
<!DOCTYPE html> <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><br> <input type="text" name="ContactName" value=""><br><br> <input type="submit" value="Submit" class="submit"> </form> } } </body> </html>