7 Replies - 280 Views - Last Post: 13 July 2014 - 01:22 AM Rate Topic: -----

#1 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-December 08

C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 07:01 AM

Posted Image

Can anyone explain me why the code doesnt go on after the < sign.

Below the part where it goes wrong there is another piece of code which is the same, when i delete the code above where it stops working, the code just works (so the part below and the < sign below just work).
I am so frustated, how can the upper part not work while it is the same, it doesnt give errors or whatever it just stops acting as C# code and goes on as HTML. anyone can help me?

Is This A Good Question/Topic? 0
  • +

Replies To: C# code in cshtml file doesnt work?!?!

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3225
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 07:14 AM

There are little wavy-lines under the two ifs, what do these say when you point at them?
Was This Post Helpful? 0
  • +
  • -

#3 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-December 08

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 10:05 AM

The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

But it really aint. But it says this because they are interpreted as markup, i wonder why and how to avoid it. i just want the whole thing to be a code block.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3225
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 10:09 AM

I know nothing about this, but isn't the code supposed to be in a block like this:
@{
    // code here
}

I interpreted from a brief look at this tutorial.

This post has been edited by andrewsw: 12 July 2014 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-December 08

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 10:43 AM

tried that, it changes nothing :(
Was This Post Helpful? 0
  • +
  • -

#6 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-December 08

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 11:31 AM

This is when i deleted the first foreach and then it just goes allright, while the second foreach is exactly the same as the first, anyone has a clue?
Posted Image
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3225
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: C# code in cshtml file doesnt work?!?!

Posted 12 July 2014 - 01:38 PM

I cannot account for the error but you could re-write the code so that the if-statement only sets products to either a new list or the existing cart-items. Then, following this, there would be a single loop that adds items to the cart.

As I say, this doesn't explain the error but at least you would have working code.
Was This Post Helpful? 0
  • +
  • -

#8 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-December 08

Re: C# code in cshtml file doesnt work?!?!

Posted 13 July 2014 - 01:22 AM

I kept that thing for what it is and wanted to go continue to search for an answer later, but the same problem is happening again now on a different place. No one has a clue? pleasseeeee
Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1513: } expected

Source Error:


Line 29:             }
Line 30:             @MvcHtmlString.Create("<li>Totaalprijs: " + totaalprijs + "</li><a href='/order'>afrekenen</a>");
Line 31:          }
Line 32: 
Line 33:         public int alreadyprocessed(Webshop.Models.Product p, List<Webshop.Models.Product> alreadyHad){



the line the error points to is line 31, but on that line there is an }, it just doesnt interpreted it or whatever?!?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1