This is the Code I'm having problems with:
@{int i = 1;}
@foreach (var item in Model)
{
@:<ul id="sortablei" class='droptrue'>
i++;
}
How can I use i in the id sortablei? I tried: @i or @{i} but it seems without a space before the i its not working. I couldn't find an answer to my problem in the Razor Syntax Reference so I'm a bit clueless right now.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Brackets:
@:<ul id="sortable@(i)" class='droptrue'>
The brackets here scope the razor expression; in many cases they aren't required, however they are necessary when:
abc@def
- this has special handling to avoid breaking pages with email addresses in themsomething like this:
@model System.Generic.Collections.List<MyNameSpace.Product>
@{
int i = 1;
string sortablei = "abc",
droptrue = "abc-cls";
}
<ul id="@sortablei" class="@droptrue">
@foreach (var item in Model)
{
<li>@item.Qty x @item.Name</li>
i++;
}
</ul>
Here's a quick reference for your knowledge.
Seams like I didn't got it right,
as Mark said, all you need to do is surround the variable with brackets like
sortable@(i)
I hope the reference is somewhat useful, as your particular problem can be found in Explicit Expression example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With