Skip to content

Commit

Permalink
Merge pull request #2 from geekinsta/razor-syntax
Browse files Browse the repository at this point in the history
Basic razor syntax
  • Loading branch information
geekinsta committed Aug 26, 2020
2 parents 135ca68 + 3d3e735 commit 4d9dfb2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
15 changes: 15 additions & 0 deletions BlazorApp/Client/Helpers/ConsoleHelper.cs
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);
}
}
}
61 changes: 59 additions & 2 deletions BlazorApp/Client/Pages/Index.razor
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},
};
}
1 change: 1 addition & 0 deletions BlazorApp/Client/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
@using Microsoft.JSInterop
@using BlazorApp.Client
@using BlazorApp.Client.Shared
@using Helpers;

0 comments on commit 4d9dfb2

Please sign in to comment.