我的页面包含以下代码:
@{
var db= Database.Open("Surgestuff");
var sqlQ = "SELECT * FROM Comments";
var data = db.Query(sqlQ);
Page.Title = "Add Comment";
}
@{
var CommenterrorMessage = "";
var LengtherrorMessage = "";
var date = @DateTime.Now;
if (IsPost) {
var CommName = "";
var Comment = "";
CommName=Request["formName"];
Comment=Request["formComm"];
var Dt = @DateTime.Now;
var isValid = true;
if (Comment.IsEmpty()){
CommenterrorMessage = "This field is required";
isValid = false;
}
else if (Comment.Length > 400){
LengtherrorMessage = "Comment must be less than 400 characters";
isValid = false;
}
else if (CommName.IsEmpty()){
CommName = "Anonymous";
}
if (isValid){
var SQLINSERT = "INSERT INTO Comments (Name, Comment, Dt) " + "VALUES (@0, @1, @2)";
db.Execute(SQLINSERT, CommName, Comment, Dt);
Response.Redirect("~/Comments");
}
else
{
<p class="message error">Please correct the errors and resubmit the form.</P>
}
}
}
<fieldset><legend>Add Comment</legend>
<form action="" method="post" enctype="multipart/form-data">
Name:
<p><input type="text" id="Name" name="formName"/></p>
Comment:
<p><textarea cols="35" rows="5" id="Comment" name="formComm"/></textarea></p>
@if(!CommenterrorMessage.IsEmpty()) {
<label for="formComm" class="validation-error">
@CommenterrorMessage
</label>
}
@if(!LengtherrorMessage.IsEmpty()) {
<label for="formComm" class="validation-error">
@LengtherrorMessage
</label>
}
<p><input type="submit" value="Add Comment" /></p>
</form>
</fieldset>
当我尝试运行此页面时,它给了我错误:
' "2" 在代码块的开头无效。只有标识符、关键字、注释、“(”和“{”是有效的。'当我查看 webmatrix 中的文件工作区时,它会将第一个关闭的“}”识别为整个代码块的结尾,然后忽略其余部分,直到它得到到“@2”。在我升级到 webmatrix 2.0 之前,我的网站上有完全相同的代码。我该如何解决这个问题?