私のソリューションは、パウロの要件とは少し異なっています。
ファイルDynamicData \ PageTemplates \ Insert.aspx.cs共有フィールドを持つテーブルに新しいレコードのデフォルトを表示するように編集しました。ユーザーはまだ他のものを挿入することができます。既存の値を持つ編集レコードの場合
public partial class Insert : System.Web.UI.Page
{
protected MetaTable table;
protected void Page_Init(object sender, EventArgs e)
{
table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
var values = table.GetColumnValuesFromRoute(Context);
// set default values for meta data of new records across all tables
// unknown values will be skipped
values.Add("creationDate", DateTime.Now);
values.Add("modificationDate", DateTime.Now);
values.Add("modificationUser", HttpContext.Current.User.Identity.Name.Substring(
HttpContext.Current.User.Identity.Name.IndexOf("\\") + 1));
FormView1.SetMetaTable(table, values);
DetailsDataSource.EntityTypeFilter = table.EntityType.Name;
}
[...]
}
は、私はいくつかのDynamicData \ FieldTemplatesファイルに変更を加えました。
public partial class Text_EditField : System.Web.DynamicData.FieldTemplateUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// ...
// show current user as value for the modification user upon editing records
if (Column.Name == "modificationUser")
{
FieldValue = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1);
}
}
[...]
}
編集時に更新された値がページに表示されますが、更新後も変更が維持されません。編集ページのテンプレートをさらに変更する必要があります。
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
// make sure a meta data update is always triggered by setting a different old value
// required for the edit components
if (e.OldValues.Contains("modificationUser"))
{
e.OldValues["modificationUser"] = string.Empty;
e.OldValues["modificationDate"] = DateTime.MinValue;
}
}
あなたがしていることのより詳細な説明:[Entity Frameworkを使用したASP.NET Dynamic Data Webサイトへの挿入前の値の更新](http://batesits.com/tag/dynamic-data/) – ofthelit