26 มกราคม 2567

Vฺisual Studio 2022 C# Blazor - 01

// youtube : https://youtu.be/dY_AWdCzsCY?si=eQyqwMcRINbhvUYz
// index.razor

@page "/"
@rendermode InteractiveServer 

<h3>Hello, @userName</h3>
<h3>@GetUserName()</h3>
<p>Sum : @GetSum()</p>
<button @onclick = "ChgName">Change Name</button>

@if (testNum == 1)
{
    <p>Num is 1</p>
else {
    <p>Num is not 1</p>
}
@foreach(var name in names)
{
    <p>@((MarkupString)name)</p>
}

@code {
    private string userName = "John";
    private int testNum = 10;
    private List<string> names;

    private string GetUserName()
    {
        return userName + "ซำบายดีไหม?";
    }

    private int GetSum()
    {
        return 2 + 2 + 3;
    }

    private void ChgName()
    {
        userName = "เกษม";
    }

    protected override void OnInitialized()
    {
        base.OnInitialized();
        names = new List<string>
        {
            "<b>Value 01<b>",
            "Value 02",
            "Value 03",
            "Value 04",
            "Value 05",
            "<i>Value 06<i>",
            "Value 07",
            "Value 08",
            "Value 09",
            "Value 10"
        };
    }
}

ไม่มีความคิดเห็น:

"I Believe in You"

Copyright(c) 2007 - 2022 by Kasem Kamolchaipisit.