2017-02-28 11 views
0

PHPからASP.netを使用してコードを変換しようとしました。C#.aspx Webフォームでフォーム応答を取得しようとしています

現在、フォームから投稿されたデータを取得するために、次のコードを試しています。

<%@ 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" then 
header('Location:VolvoHomepage.html');End If 
If Request.Form["Car"] == "Ford" then 
header('Location:FordHomepage.html');End If 
If Request.Form["Car"] == "Mercedes" then 
header('Location:MercedesHomepage.html');End If 
If Request.Form["Car"] == "Audi" then 
header('Location:AudiHomepage.html');End If 
If Request.Form["Car"] == "Vauxhall" then 
header('Location:VauxhallHomepage.html');End If 
%> 

</body> 
</html> 

しかし、私は "/ 'アプリケーションでサーバーエラーを受けています。"

誰でも助けてください。

+0

エラーの詳細をもっと詳しく説明する必要があります。完全なスタックトレースが必要です。それは何と言いますか?それは、ヘッダ( 'Location:MercedesHomepage.html');はPHPの構文であり、.NETではないからです。 Response.Redirect( "MercedesHomepage.html") '私は思うべきです。 – ADyson

答えて

1

この行は、あなたがC#言語でコーディングされていることを言っている:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CarPage.aspx.cs" Inherits="Ass2.CarPage"%>

しかし、あなたは、Visual BasicおよびPHP言語のミックスを使用しているの下:C#ので

<% If Request.Form["Car"] == "Volvo" then 
header('Location:VolvoHomepage.html');End If 
%> 

コード

<% if (Request.Form["Car"] == "Volvo") { 
    // do your thing 
} 
%> 

ただし、Webフォームフレームワークでaspxファイルの "ユーザーコントロール"を宣言し、aspx.csファイルに "ロジック"をコーディングする必要があります。あなたのASPXコードは次のようになります。

<myUserControls:VolvoHomepage runat="server" id="_ucVolvo" visible="false" /> 
<myUserControls:FordHomepage runat="server" id="_ucFord" visible="false" /> 
... 

あなたのHTML対応するユーザーコントロールのファイルの各コードをコピー/ペーストします。

そしてユーザーコントロールが表示されているかどうか、今CarPage.aspx.csの(例えば)Page_Loadメソッドを定義することができます。

protected void Page_Load(object sender, eventargs e) { 
    if (Request.Form["Car"] == "Volvo") _ucVolvo.Visible = true; 
    else if (Request.Form["Car"] == "Ford") _ucFord.Visible = true; 
} 

はそれがより明確ですか?

+0

ありがとうございます –

関連する問題