admin管理员组文章数量:1025259
Ok, so I am VERY NEW at Blazor (coming from old school Webforms), and have a simple Web App (InteractiveAuto) where I am testing simply binding values to a class. It's not working, when I tab out of the MudTextFields the corresponding MudText does not update. I know it is a very noob situation, but can anyone slap me a tell me why?
@page "/"
<PageTitle>Home</PageTitle>
<MudAlert Severity="Severity.Error">You are delinquent on your payments.</MudAlert>
<h1>Hello, world!</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<br />
<MudTextField T="string" @bind-Value="testClass.Name"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter"></MudTextField>
Welcome to your new app.
@code {
MyData testClass = new MyData
{
Id = 1,
Name = "Jimmy",
Counter = 5
};
class MyData
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Counter { get; set; }
}
}
Ok, so I am VERY NEW at Blazor (coming from old school Webforms), and have a simple Web App (InteractiveAuto) where I am testing simply binding values to a class. It's not working, when I tab out of the MudTextFields the corresponding MudText does not update. I know it is a very noob situation, but can anyone slap me a tell me why?
@page "/"
<PageTitle>Home</PageTitle>
<MudAlert Severity="Severity.Error">You are delinquent on your payments.</MudAlert>
<h1>Hello, world!</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<br />
<MudTextField T="string" @bind-Value="testClass.Name"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter"></MudTextField>
Welcome to your new app.
@code {
MyData testClass = new MyData
{
Id = 1,
Name = "Jimmy",
Counter = 5
};
class MyData
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Counter { get; set; }
}
}
Share
Improve this question
asked Dec 17, 2024 at 15:53
Robert BenedettoRobert Benedetto
1,7105 gold badges32 silver badges58 bronze badges
2 Answers
Reset to default 0Had to add a form and now it works.
<MudForm Model="@testClass"></MudForm>
I see you've answered yourself but you don't need to add a form to bind values to a class object.
In MudBlazor the input components by default only get their values bound when you press Enter or when it loses focus i.e. The input is not selected anymore.
If you add the Immediate="true"
property to the component then it will bind immediately as you type. This works for any input component in MudBlazor.
<h1>Bind immediate</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<hr/>
<MudTextField T="string" @bind-Value="testClass.Name" Immediate="true"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter" Immediate="true"></MudTextField>
Demo Snippet
Ok, so I am VERY NEW at Blazor (coming from old school Webforms), and have a simple Web App (InteractiveAuto) where I am testing simply binding values to a class. It's not working, when I tab out of the MudTextFields the corresponding MudText does not update. I know it is a very noob situation, but can anyone slap me a tell me why?
@page "/"
<PageTitle>Home</PageTitle>
<MudAlert Severity="Severity.Error">You are delinquent on your payments.</MudAlert>
<h1>Hello, world!</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<br />
<MudTextField T="string" @bind-Value="testClass.Name"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter"></MudTextField>
Welcome to your new app.
@code {
MyData testClass = new MyData
{
Id = 1,
Name = "Jimmy",
Counter = 5
};
class MyData
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Counter { get; set; }
}
}
Ok, so I am VERY NEW at Blazor (coming from old school Webforms), and have a simple Web App (InteractiveAuto) where I am testing simply binding values to a class. It's not working, when I tab out of the MudTextFields the corresponding MudText does not update. I know it is a very noob situation, but can anyone slap me a tell me why?
@page "/"
<PageTitle>Home</PageTitle>
<MudAlert Severity="Severity.Error">You are delinquent on your payments.</MudAlert>
<h1>Hello, world!</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<br />
<MudTextField T="string" @bind-Value="testClass.Name"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter"></MudTextField>
Welcome to your new app.
@code {
MyData testClass = new MyData
{
Id = 1,
Name = "Jimmy",
Counter = 5
};
class MyData
{
public int Id { get; set; }
public string Name { get; set; } = "";
public int Counter { get; set; }
}
}
Share
Improve this question
asked Dec 17, 2024 at 15:53
Robert BenedettoRobert Benedetto
1,7105 gold badges32 silver badges58 bronze badges
2 Answers
Reset to default 0Had to add a form and now it works.
<MudForm Model="@testClass"></MudForm>
I see you've answered yourself but you don't need to add a form to bind values to a class object.
In MudBlazor the input components by default only get their values bound when you press Enter or when it loses focus i.e. The input is not selected anymore.
If you add the Immediate="true"
property to the component then it will bind immediately as you type. This works for any input component in MudBlazor.
<h1>Bind immediate</h1>
<MudText>@testClass.Id</MudText>
<MudText>@testClass.Name</MudText>
<MudText>@testClass.Counter</MudText>
<hr/>
<MudTextField T="string" @bind-Value="testClass.Name" Immediate="true"></MudTextField>
<MudTextField T="int" @bind-Value="testClass.Counter" Immediate="true"></MudTextField>
Demo Snippet
本文标签: blazorTrying to bind value and displaynot workingStack Overflow
版权声明:本文标题:blazor - Trying to bind value and display, not working - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1735995240a1376293.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论