简体   繁体   中英

Using C# and Blazor.... I want to be able to determine what the user selected

Here is my pretty simple C# code. Writing some software for my martial arts club

Why do I get an error on this line

HoldTechnique = Techniques.SelectedIndex.ToString();

it says

Techniques does not exist in current context

This is in my Terms.razor file:

@page "/Terms"

<select id="Techniques" name="Techniques" runat="server" @onchange="MyVideoSrc">
    <option>Shihonage</option>
    <option>Kytenage</option>
    <option>Kotegeshi</option>
    <option>Tynohenko</option>
</select>

@code {
    private void MyVideoSrc()
    {
        string HoldTechnique = "";
        HoldTechnique = Techniques.SelectedIndex.ToString();
    }
}

I did not get much help... well ... Actually no help at all from here. I just got: "....go look at some basic concepts before posting here...." I have coded for many years and I am just not familiar with How some of the stuff worked in C#/Html/Blazor.... I just wanted help with a little direction to get me pointed in the RIGHT direction. So for those who are starting out like I am .... If you are wondering it it actually pretty simple. I have done a lot of work with Forms especially .NET/VB... if you have a basic select statement (mine has Japanese terms)

<select @onchange="@DoStuff">
    <option Value="Shihonage">Shihonage </option>
    <option Value="Kytenage">Kytenage </option>
    <option Value="Kotegeshi">Kotegeshi </option>
    <option Value="Sankyo">Sankyo </option>
</select>

Here is your function to define your variables

@functions
        {
    public string selectedString = "Ikyo";

}

Here is your code for "DoStuff" - eventually this will be a class.. Right now it is all in the .razor file

void DoStuff(ChangeEventArgs e)
    {
        selectedString = e.Value.ToString();
        Console.WriteLine("It is definitely: " + selectedString);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM