Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:34:50+00:00 2026-06-07T00:34:50+00:00

My page consists of the following code: @{ var db= Database.Open(Surgestuff); var sqlQ =

  • 0

My page consists of the following code:

@{
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>

And when i try to run this page it gives me the error:

‘ “2” is not valid at the start of a code block. Only identifiers, keywords, comments, “(” and “{” are valid. ‘
When i look at the files workspace in webmatrix it recognises the first closing “}” as the end for the whole code block then disregards the rest until it gets to “@2”. I have had the exact same code working on my website before i upgraded to webmatrix 2.0. How can i fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:34:51+00:00Added an answer on June 7, 2026 at 12:34 am

    I finally copy/pasted your code into WebMatrix (on my Virtual Box). You have 2 @DateTime.Nows inside your Razor @{ ... } code. if you change them to:

    ... = DateTime.Now;
    

    it solves the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I want the ‘select file’ dialog to open when a
I am getting the following error on my Facelet page, which simply consists of
I've a mobile page developed with ExtLib mobile controls: http://hostname/mydb.nsf/MobileTest.xsp The page consists of
I have a page that consists of a header div for navigation, a content
I have a web page that consists of a checkbox (parent) and on this
my website consists only of one page where all other pages are loaded in
Basically I have a series of projects displayed on the page. Each project consists
I have a arraylist of employees from the gridview in my ASP.net Page as
In the following code protected void Page_Load(object sender, EventArgs e) { List<string> listSetValues =
I have a small testview in Silverlight which consists of the following grid: <Grid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.