In der Blazor-Anwendung, die ich erstelle, habe ich den folgenden cshtml-Code, der ein <input>
-Element enthält, damit der Benutzer seinen Namen eingeben kann. Ich möchte in der Lage sein, den Wert des Eingabeelements an die Name-Eigenschaft im Abschnitt c # -Funktionen der Blazor-Seite zu binden.
Wie würde ich das tun?
Mein Code ist wie folgt:
@page "/nameUpload"
<p>
//This is the input element that I would like to bind
Enter your name: <input type="text" ><br />
</p>
@functions {
//This is the property that I want to bind the input to
private string Name { get; set; } = "";
}
Verwenden Sie das @bind
Attribut mit einer input
.
@page "/nameUpload"
<p>
@* This is the input element that I would like to bind *@
Enter your name: <input type="text" @bind(name) />
<br />
</p>
@functions {
@* This is the property that I want to bind the input to *@
string name;
}