「MPP に接続して既存のドライバー ID を探す」の下にある If Else ブロックにより、メインの Razor ブロックで一致しない中かっこが発生しています。私は何かが欠けていることを知っていますが、それを理解することはできません. デバッガーは最後の中かっこを無視し、最後の中かっこの 2 つ前が @{ 開き中かっこと一致していると見なします。
@{
Layout = "~/Shared/_Layout.cshtml";
Page.Title = "Register";
// Setup field validation
Validation.RequireField("driverfirstname", "Cannot be blank.");
Validation.RequireField("driverlastname", "Cannot be blank.");
Validation.RequireField("driverssn", "Cannot be blank.");
// Initialize variables
var driverfirstname = "";
var driverlastname = "";
var driverssn = "";
// If validation is OK
if (IsPost && Validation.IsValid())
{
driverfirstname = @Request.Form["driverfirstname"];
driverlastname = @Request.Form["driverlastname"];
driverssn = @Request.Form["driverssn"];
// Create Driver ID and Password
string first = driverfirstname.Substring(0, 3);
string last = driverlastname.Substring(0, 3);
string lastFour = driverssn.Substring(7, 4);
string drivercodetest = (last + first).ToUpper();
// Connect to MPP and look for existing Driver IDs
var dbs = Database.Open("other_db");
var drivercodempp = dbs.Query("SELECT mpp_id FROM profile WHERE mpp_id = @drivercodetest");
var drivercode = "";
if (drivercodempp == null)
{
drivercode = (last + first).ToUpper();
}
else if (drivercodempp.Contains("01"))
{
drivercode = (last + first).ToUpper() + "02";
}
else if (drivercodempp.Contains("02"))
{
drivercode = (last + first).ToUpper() + "03";
}
else if (drivercodempp.Contains("03"))
{
drivercode = (last + first).ToUpper() + "04";
}
else if (drivercodempp.Contains("04"))
{
drivercode = (last + first).ToUpper() + "05";
}
else if (drivercodempp.Contains("05"))
{
drivercode = (last + first).ToUpper() + "06";
}
else
{
drivercode = (last + first).ToUpper() + "07";
}
// Submit to database
var dbi = Database.Open("MainDB");
var insertCommand = "INSERT INTO driver (drivercode, driverfirstname, driverlastname, driverssn) VALUES(@0, @1, @2, @3)";
dbi.Execute(insertCommand, drivercode, driverfirstname, driverlastname, driverssn);
Response.Redirect("~/confirm_register");
}
}