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 7748597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:49:32+00:00 2026-06-01T10:49:32+00:00

While trying to validate my forms i get the following error: Expected a {

  • 0

While trying to validate my forms i get the following error:
Expected a “{” but found a “(“. Block statements must be enclosed in “{” and “}”. You cannot use single-statement control-flow statements in CSHTML pages.
My lines of code for this page are:

@{
var db= Database.Open("Games");
var sqlQ = "SELECT * FROM Games";
var data = db.Query(sqlQ);   
}
@{
    var fileerrorMessage = "";
    var NameerrorMessage = "";
    var Gamefile = "";
    var GameName = "";
    var isValid = true;
    if (IsPost) {
        if (file.IsEmpty()){
        fileerrorMessage = "Please upload a file.";
        isValid = false;
        }

    else (formName.IsEmpty()){
        NameerrorMessage = "Please give the game a name.";
        isValid = false;
    }

    if (isValid){
    var fileData = Request.Files[0];
    var fileName = Path.GetFileName(fileData.FileName);
    var fileSavePath = Server.MapPath("~/upload/" + fileName);
    fileData.SaveAs(fileSavePath);
    GameName=Request["formName"];
    Gamefile=fileName;
    var SQLINSERT = "INSERT INTO Games (Name, file_path) " + "VALUES (@0, @1)";
    db.Execute(SQLINSERT, GameName, Gamefile);
    Response.Redirect("default.cshtml");
    }

    else
    {
        <p class="message error">Please correct the errors and resubmit the form.</P> 
    }

    }
}
<form action="" method="post" enctype="multipart/form-data">

  <input type="file" name="file" id="file" /><p>
    @if(!fileerrorMessage.IsEmpty()) {
        <label for="file" class="validation-error">
            @fileerrorMessage
        </label>
    }
  <p><input type="text" name="formName" value="@GameName" />
     @if(!NameerrorMessage.IsEmpty()) {
        <label for="file" class="validation-error">
            @NameerrorMessage
        </label>
     }

  <input type="submit" value="Add Game" />
</form>

The error page says that the error is with line 18 which suggests there is something wrong with: if (file.IsEmpty()){

  • 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-01T10:49:34+00:00Added an answer on June 1, 2026 at 10:49 am
    else (formName.IsEmpty()){
        NameerrorMessage = "Please give the game a name.";
        isValid = false;
    

    should be:

    else if (formName.IsEmpty()){
        NameerrorMessage = "Please give the game a name.";
        isValid = false;
    

    the if is missing!

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

Sidebar

Related Questions

While trying to validate form data on my page i get the following error:
I am trying to create a validate-email javascript and get it working with forms
I'm trying to validate a form of a test. I get an error in
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
I am trying to validate weather the connection was successful but have been getting
I am following alloy-complex-form-examples from github trying to learn nested forms and I just
I receive the following Exception while trying to send an email (using Seam) Caused
While trying to answer a question in the vicinity ' Unit Testing WPF Bindings
While trying to use LINQ to SQL I encountered several problems. I have table
While trying to connect to a database that's set to read only, the connection

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.