次の解決策を実行しました。「ReflectionHelper」クラスはモデルのプロパティを反映し、「properties」変数にはモデルフィールド{{'Id'、1}、{'Name'、'Myname'}など}があります。
public static class ReflectionHelper
{
public static void IterateProps(Object obj, string baseProperty, ref Dictionary<string,object> properties )
{
if (obj != null)
{
var baseType = obj.GetType();
var props = baseType.GetProperties();
foreach (var property in props)
{
var name = property.Name;
var propType = property.PropertyType;
if (propType.IsClass && propType.Name != "String")
{
IterateProps(property.GetValue(obj, null), baseProperty + "." + property.Name, ref properties);
}
else
{
properties.Add(baseProperty + "." + name, property.GetValue(obj, null));
}
}
}
}
}
そして、私は次のことを考えています。
@using (Html.BeginForm("MyStep1", "Wizard"))
{
var properties = new Dictionary<string, object>();
ReflectionHelper.IterateProps(Model, Model.GetType().Name,ref properties);
foreach (var property in properties)
{
<input type="hidden" name="@property.Key" value="@property.Value"/>
}
}
これはウィザードソリューションの一部です。後でMVCでウィザードに関する記事を書く予定ですが、誰かが役立つかもしれません。