今それを回避するために私の方法を働いた。FormCollection
今では継承する代わりに、独自のフィールド' form
'があります。これはFormCollection
代わりに、コマンドはそれに基づいて動作します。
編集:
人々はコードを求めていたので、ここに古いクラスがあります:
using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using OpenProjects.Core;
namespace ProjectSupport.Web.Test
{
public class FormFor<TEntity> : FormCollection where TEntity : class
{
public FormFor<TEntity> Set<TReturn>(Expression<Func<TEntity, TReturn>> property, string value)
{
this[property.PropertyName()] = value;
return this;
}
}
}
そして、これが今の状況です。
using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using OpenProjects.Core;
namespace ProjectSupport.Web.Test
{
public class FormFor<TEntity> where TEntity : class
{
private FormCollection form;
public FormFor()
{
form = new FormCollection();
}
public FormFor<TEntity> Set<TResult>(Expression<Func<TEntity, TResult>> property, string value)
{
form.Add(property.PropertyName(), value);
return this;
}
public FormCollection ToForm()
{
return form;
}
}
}
モデルバインダーではなくこれが使用された理由を明確にするために、これはフォームをすばやく簡単にモックアップするためのテストにのみ使用されていました。