0% found this document useful (0 votes)
28 views5 pages

Latihan Soal Asp Net Minggu 2

The document provides examples of Razor code for forms, loops, arrays, and conditional statements. It includes a form to add two numbers, loops like for, foreach, while, and arrays. It also covers conditional logic like if/else, else if, and switch statements.

Uploaded by

riski.adi7734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Latihan Soal Asp Net Minggu 2

The document provides examples of Razor code for forms, loops, arrays, and conditional statements. It includes a form to add two numbers, loops like for, foreach, while, and arrays. It also covers conditional logic like if/else, else if, and switch statements.

Uploaded by

riski.adi7734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LATIHAN SOAL

Buatlah Web From Razor dengan nama Tambah, codenya sbb :

@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Latihan 1 Form</title>
</head>
<body>
@{
if (IsPost)
{
string bil1 = Request["Bil1"];
string bil2 = Request["Bil2"];
int hasil = bil1.AsInt() + bil2.AsInt();
<form method="post" action="">
Bilangan 1 :<br>
<input type="text" name="CompanyName" value="@bil1"><br>
Bilangan 2 :<br>
<input type="text" name="ContactName" value="@bil2"><br>
Hasilnya :<br>
<input type="text" name="ContactName1" value="@hasil"><br><br>
</form>
}
else
{
<form method="post" action="">
Bilangan 1 :<br>
<input type="text" name="Bil1" value=""><br>
Bilangan 2 :<br>
<input type="text" name="Bil2" value=""><br><br>
<input type="submit" value="+" class="submit">
</form>
}
}
</body>
</html>
Latihannya, Buatlah Form, untuk menghitung Luas Bangun Datar Sbb :

Contoh Designnya Sbb :

FORMULIR LUAS DAN KELILING PERSEGI


Sisi :
Luas :
Keliling :
Hitung
 Hitung adalah Tombol (Button), dimana setelah mengisi Sisi, klik hitung maka akan muncul Luas dan
Kelilingnya
Contoh Looping Razor C#
For Loop :
<!DOCTYPE html>
<html>
<body>
<h1>Hello Web Pages</h1>
<p>The time is @DateTime.Now</p>
</body>
</html>

For Each Loop :


<html>
<body>
<ul>
@foreach (var x in Request.ServerVariables)
{<li>@x</li>}
</ul>
</body>
</html>

While Loop :
<html>
<body>
@{
var i = 0;
while (i < 5)
{
i += 1;
<p>Line @i</p>
}
}
</body>
</html>

Array :
@{
string[] members = {"Jani", "Hege", "Kai", "Jim"};
int i = Array.IndexOf(members, "Kai")+1;
int len = members.Length;
string x = members[2-1];
}
<html>
<body>
<h3>Members</h3>
@foreach (var person in members)
{
<p>@person</p>
}
<p>The number of names in Members are @len</p>
<p>The person at position 2 is @x</p>
<p>Kai is now in position @i</p>
</body>
</html>

If Condition :
@{var price=50;}
<html>
<body>
@if (price>30)
{
<p>The price is too high.</p>
}
</body>
</html>

If Else Condition :
@{var price=20;}
<html>
<body>
@if (price>30)
{
<p>The price is too high.</p>
}
else
{
<p>The price is OK.</p>
}
</body>
</html>

Else If Condition :
@{var price=25;}
<html>
<body>
@if (price>=30)
{
<p>The price is high.</p>
}
else if (price>20 && price<30)
{
<p>The price is OK.</p>
}
else
{
<p>The price is low.</p>
}
</body>
</html>
Switch Condition :
@{
var message="";
var weekday=DateTime.Now.DayOfWeek;
var day=weekday.ToString();
}
<html>
<body>
@switch(day)
{
case "Monday":
message="This is the first weekday.";
break;
case "Thursday":
message="Only one day before weekend.";
break;
case "Friday":
message="Tomorrow is weekend!";
break;
default:
message="Today is " + day;
break;
}
<p>@message</p>
</body>
</html>

You might also like