-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from geekinsta/razor-syntax
Basic razor syntax
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorApp.Client.Helpers | ||
{ | ||
public class ConsoleHelper | ||
{ | ||
public static void WriteToConsole(string text = "Hi form Blazor App") | ||
{ | ||
Console.WriteLine(text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,64 @@ | ||
@page "/" | ||
@*@using Helpers;*@ | ||
|
||
<h1>Hello, world!</h1> | ||
<h1>@message</h1> | ||
<h2>Message is @GetLength(message) chars long.</h2> | ||
<h2>@(message + " Geekinsta")</h2> | ||
|
||
<button class="btn btn-primary" @onclick="@(() => message = "You clicked me")">Click Me</button> | ||
|
||
<button class="btn btn-success" @onclick="@(() => MyClass.WriteToConsole())">Write to console</button> | ||
|
||
<button type="button" class="btn btn-info" @onclick="@(()=> ConsoleHelper.WriteToConsole())">Call console helper</button> | ||
|
||
<h1>Customers</h1> | ||
@foreach(var customer in Customers) | ||
{ | ||
<div class="card mb-3"> | ||
<div class="card-header"> | ||
@customer.Name | ||
@if (customer.IsSubscribedToNewsletter) | ||
{ | ||
<span class="badge badge-success">Subscribed</span> | ||
} | ||
else | ||
{ | ||
<span class="badge badge-danger">Not subscribed</span> | ||
} | ||
</div> | ||
<div class="card-body">@customer.Email</div> | ||
</div> | ||
} | ||
|
||
Welcome to your new app. | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?" /> | ||
@code{ | ||
string message = "Hello, World!"; | ||
|
||
int GetLength(string text) | ||
{ | ||
return text.Length; | ||
} | ||
|
||
public class MyClass | ||
{ | ||
public static void WriteToConsole(string text = "Message from MyClass") | ||
{ | ||
Console.WriteLine(text); | ||
} | ||
} | ||
|
||
public class Customer | ||
{ | ||
public string Name { get; set; } | ||
public string Email { get; set; } | ||
public bool IsSubscribedToNewsletter { get; set; } | ||
} | ||
|
||
List<Customer> Customers = new List<Customer>() | ||
{ | ||
new Customer(){Name= "John Doe", Email="john@mail.com", IsSubscribedToNewsletter=true}, | ||
new Customer(){Name= "Jane Doe", Email="jane@mail.com", IsSubscribedToNewsletter=true}, | ||
new Customer(){Name= "Janet Doe", Email="janet@mail.com", IsSubscribedToNewsletter=false}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
@using Microsoft.JSInterop | ||
@using BlazorApp.Client | ||
@using BlazorApp.Client.Shared | ||
@using Helpers; |