8 Replies - 1988 Views - Last Post: 14 August 2014 - 07:13 AM Rate Topic: -----

#1 koeshkoesh  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • 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

  • It's just been revoked!
  • member icon

Reputation: 3805
  • View blog
  • Posts: 13,485
  • 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: 59
  • 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

  • It's just been revoked!
  • member icon

Reputation: 3805
  • View blog
  • Posts: 13,485
  • 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: 59
  • 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: 59
  • 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

  • It's just been revoked!
  • member icon

Reputation: 3805
  • View blog
  • Posts: 13,485
  • 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: 59
  • 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
  • +
  • -

#9 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

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

Posted 14 August 2014 - 07:13 AM

I realize this is a bit late, but here's my 2 cents on this.

First, it looks like you are putting too much logic inside the view. Most of that logic should be handled in the controller and the results returned to the view to be displayed. This would completely remove any template problems being caused by trying to stack so many if and for statements. It looks like you are updating a shopping cart, why would this be logic that belongs in the view?

Second, the current code is susceptible to errors because you are trying to parse values without doing any checks to see whether they exist and if they do exist are they a value that can be parsed into an integer.

Also, as to your last post, there may be a } on that line, but you're still missing a } somewhere within that block.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1