投稿されたデータをHTMLフォームからC#ページに取り出そうとしています。フォームデータをC#で取得したときのパーサーエラー
私は、このエラーが発生しますが:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: 'Ass2.CarPage' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CarPage.aspx.cs" Inherits="Ass2.CarPage"%>
Line 2:
Line 3:
HTMLコード:
<!--Car Search Form-->
<div id="Search_Form">
<form name="Car Search" action="CarPage.aspx" method="post">
<h1 align="center">Search For A Car Now: </h1>
<h2 align="center">
<select name="Car">
<option value="Volvo">Volvo</option>
<option value="Ford">Ford</option>
<option value="Mercedes">Mercedes</option>
<option value="Audi">Audi</option>
<option value="Vauxhall">Vauxhall</option>
</select>
<h1 align="center">
<input type="Submit" value="Submit">
</h1>
</form>
</div>
C#コード:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CarPage.aspx.cs" Inherits="Ass2.CarPage"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<%
if (Request.Form["Car"] == "Volvo")
{
Response.Redirect("VolvoHomepage.html");
}
if (Request.Form["Car"] == "Ford")
{
Response.Redirect("FordHomepage.html");
}
if (Request.Form["Car"] == "Mercedes")
{
Response.Redirect("MercedesHomepage.html");
}
if (Request.Form["Car"] == "Audi")
{
Response.Redirect("AudiHomepage.html");
}
if (Request.Form["Car"] == "Vauxhall")
{
Response.Redirect("VauxhallHomepage.html");
}
%>
</body>
</html>
ASPX.CSコード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
同じページに 'C#'と 'VB'コードを書かないことから始めます。 'End If'を削除してください。 – VDWWD
@VDWWD - これを試しましたが、エラーメッセージを停止しません –
あなたは私たちにコードビハインドページを表示していません。 – mason