[英]Use the same bind-Value for two properties
Hi I have a question that looks simple but I don't have an answer to it.嗨,我有一个看起来很简单的问题,但我没有答案。 I have a model like this:
我有一个像这样的 model:
public class Employee
{
[Display(Name ="Firstname")]
public string FirstName { get; set; }
[Display(Name ="surname")]
public string LastName{ get; set; }
//Ohter attributes
}
And I need to add FullName
like this:我需要像这样添加
FullName
:
[Display(Name = "FullName")]
public string FullName=> $"{FirstName } {LastName}";
So I can use it in inputText like this:所以我可以像这样在 inputText 中使用它:
<InputText id="FullName" @bind-Value="Employee.FullName" />
but I can't do that because I need a setter otherwise I will get an error.但我不能这样做,因为我需要一个二传手,否则我会得到一个错误。
Thanks for help感谢帮助
You can use FullName
one-way binding to display the information.您可以使用
FullName
单向绑定来显示信息。 To edit you need the property setter, how would the application know which part of the inputed text is FirstName
and LastName
?要进行编辑,您需要属性设置器,应用程序如何知道输入文本的哪一部分是
FirstName
和LastName
? Better approach is to use individual inputs, or if you really want to make it work like that you could take the TextChangedEvent
and read/split the string however you want and then set values to FirstName
and LastName
.更好的方法是使用单独的输入,或者如果你真的想让它像这样工作,你可以使用
TextChangedEvent
并根据需要读取/拆分字符串,然后将值设置为FirstName
和LastName
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.