- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在绑定(bind)到模型值的 blazor editform 中有一个 InputSelect,并且还有一个 onchange 事件,该事件根据新值更改模型中的其他属性。
绑定(bind)到@bind-Value 和@onchange 都不起作用(我猜是因为绑定(bind)值同时使用输入的值和值更改的属性。
我可以绑定(bind)到oninput,但我想知道是否有更好的方法来做到这一点。
<InputSelect id="inputPeriod" name="inputPeriod" class="form-control" @bind-Value="model.Period" @oninput="periodChanged">
protected void periodChanged(ChangeEventArgs e)
{}
我可以像这样绑定(bind)到oninput
但理想情况下,我想在更新模型属性后绑定(bind)到 @onchange 事件,或者知道最佳实践是什么。如果不使用绑定(bind)值,模型验证将不起作用,所以我能想到的唯一替代方法是让更改事件在我的模型的属性内部工作,但这似乎是错误的
最佳答案
这是一个愚蠢的示例,您必须在其中输入您的名字,然后选择您的宠物,结果是以您亲爱的宠物为您重命名。该示例描述了如何在字段更改时操作模型:
<EditForm EditContext="@EditContext">
<DataAnnotationsValidator />
<div class="form-group">
<label for="name">Enter your Name: </label>
<InputText Id="name" Class="form-control" @bind-Value="@person.Name"></InputText>
<ValidationMessage For="@(() => person.Name)" />
</div>
<div class="form-group">
<label for="body">Select your pet: </label>
<InputSelect @bind-Value="@person.Pet">
<option value="Cat">Cat</option>
<option value="Dog">Dog</option>
<option value="Horse">Horse</option>
<option value="Lion">Lion</option>
</InputSelect>
<ValidationMessage For="@(() => person.Pet)" />
</div>
<p>
<button type="submit">Submit</button>
</p>
</EditForm>
@code
{
private EditContext EditContext;
private Person person = new Person();
protected override void OnInitialized()
{
EditContext = new EditContext(person);
EditContext.OnFieldChanged += EditContext_OnFieldChanged;
base.OnInitialized();
}
// Note: The OnFieldChanged event is raised for each field in the model
private void EditContext_OnFieldChanged(object sender, FieldChangedEventArgs e)
{
if (e.FieldIdentifier.FieldName == "Pet")
{
person.Name = person.Pet;
}
}
public class Person
{
public string ID { get; set; }
public string Name { get; set; }
public string Pet { get; set; }
}
}
the only alternative way I can think of is to have the change events working inside the properties in my model, but that seems wrong
一点也不...
没有要求模型实现 INotifyPropertyChanged,但如果它们实现了,您可以轻松地将其连接到 EditContext。这样您就无需使用内置的 Input* 组件 - 您可以改为绑定(bind)到常规 HTML 元素并仍然获得修改通知。这为 UI 的呈现方式提供了更大的灵 active ,但代价是模型类中的复杂性和样板代码更加复杂。
希望这有助于...
关于onchange - blazor editform 更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61576373/
我找到了 this article但我很难理解如何防止任何 独立提交“输入”键 Submit @code { private Exampl
我想在绑定(bind)到模型值的 blazor editform 中有一个 InputSelect,并且还有一个 onchange 事件,该事件根据新值更改模型中的其他属性。 绑定(bind)到@bi
我想制作一个具有 EditForm 的组件并将表单和验证封装在组件内部。 我想在我的应用程序中的任何地方重用这个组件并使用任何按钮提交它。 我如何提交 EditForm从它外面的按钮? 观察 :我已经
我正在使用reactjs和redux来开发仪表板。我已经完成了添加、删除,但编辑不起作用。当用户单击项目时,文本字段应显示其当前值并能够提交更改。我可以在单击时显示文本字段,但无法显示单击的该项目的当
使用 AspNet Blazor 及其 EditForm: 我正在创建一个简单的表单,它应该包含一个更新和一个删除按钮。我似乎没有找到任何关于如何将参数传递给提交的示例。 我试图在删除按钮中放置一个@
如何解决此 Blazor 服务器错误? EditForm requires either a Model parameter, or an EditContextparameter 我在下面创建了一个
我有一个名为 EditOffice 的 Blazor 组件。它看起来如下: ... Save office 我创建了名为 InputTextRow
Blazor 文档的 Form Validation example在 EditForm 中有一个提交按钮组件组件: OnValidSubmit="@HandleValidSubmit">
我试图按照从 youtube channel 创建表单的说明进行操作: https://www.youtube.com/watch?v=zfqQ_fhmPOQ 或者 https://www.youtu
我在 Blazor 应用程序中使用 EditForm 从空白表单以及已使用从数据库获取的数据进行初始化的表单提交信息。当我使用数据库中的数据初始化表单时,我想保持“提交”按钮处于禁用状态,直到发生某些
我使用下面的代码在人员选择器中添加值。该代码在 NewForm.aspx 中运行良好。但是当我在 EditForm.aspx 中编辑人员选择器时,它不会采用新值。它仅保存旧值。 function Se
我创建了一个新的、干净的 Blazor WASM 项目,并在索引页面底部添加了以下最小示例: Submit @code { public string FormModel
我有一个在单个 EditForm 中绑定(bind)到三个相关模型的表单。我希望了解如何在同一个提交中验证它们中的每一个。我已经能够成功验证单个模型,但是我在任何地方都看不到有关如何验证多个模型的任何
Blazor vRC1 EditForm 似乎有些微妙之处组件,在某些标记情况下它不会呈现其内容。例如,当 EditForm放置在 内标签, 什么都没发生 . ... @foreach(
我有一个带有选择字段的列表,它是多项选择 - 意味着有很多复选框。 我想渲染它,使其被框架包围,例如带有边框的 DIV 标签。 (该框架应位于 HTML 文档中) 如何编辑控件模板/FLDTYPES.
只需基于 EditForm 并使用 Fluent Validation 组合一个包装器即可。我在此表单上创建了两个属性,如下所示: if (ModelValidation) { editCon
当我需要帮助时,我在这里有一项任务。我想要完成的是以下.. 在 SharePoint (2013) 中隐藏 newform、editform 和 dispform 上的某些字段 我试图隐藏的字段只是输
过去一两个小时,我一直在努力寻找一种解决方案来解决我认为应该很容易做的事情以及我认为以前有人问过的事情,但也许我没有使用正确的术语。 我有一个非常基本的 RadGrid,它允许扩展行以进行编辑或显示更
我有一个小型编辑应用程序,其中包含以下文件。当我提交表单时,它显示 AttributeError: 'EditForm' object has no attribute 'validate_on_su
让我们考虑客户端 blazor 应用程序中的以下页面: @page "/test"
我是一名优秀的程序员,十分优秀!