MVVM与DataForm - 如何设置非显示字段的值

发布于 2024-09-08 11:13:19 字数 244 浏览 2 评论 0 原文

我正在使用 SL4 和 RIA 服务。我有一个包含 3 个字段的简单表(Name、UpDatedByUserId、UpDatedOn)。在我的元数据中,我对后两个字段使用数据注释,以便它们不显示。我的 DataGrid 和相关的 DataForm 正确显示每条记录,并且根据需要,DataForm 仅显示“名称”字段,但当然我想以编程方式设置其他 2 个字段(UpDatedByUserId 和 UpDatedOn)的值。有没有办法可以在 ViewModel 中设置这些值?

I'm using SL4 and RIA services. I have a simple table with 3 fields (Name, UpDatedByUserId, UpDatedOn). In my metadata I use Data Annotation on the 2 latter fields so that they do not display. My DataGrid and the related DataForm show each record correctly and, as required, the DataForm only shows the Name field but of course I want to programmatically set values for the other 2 fields (UpDatedByUserId and UpDatedOn). Is there a way I can set those values in the ViewModel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-09-15 11:13:19

在您的 ViewModel 中,您可以像这样设置您的 Name 属性:

private string _UpdatedByUserId;
private DateTime _UpdatedOn;
private string _Name;
public string Name 
{
   get { return _Name; }
   set
   {
      if(value != _Name)
      {
         _UpdatedByUserId = WebContext.Current.User.Name;
         _UpdatedOn = DateTime.Now;
         _Name = value;
      }
   }
}

In your ViewModel you could setup your Name property like so:

private string _UpdatedByUserId;
private DateTime _UpdatedOn;
private string _Name;
public string Name 
{
   get { return _Name; }
   set
   {
      if(value != _Name)
      {
         _UpdatedByUserId = WebContext.Current.User.Name;
         _UpdatedOn = DateTime.Now;
         _Name = value;
      }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文