当我尝试创建一个新的“流(Flow)”类时,控制器中嵌套的类(“行为(Action)”)总是返回为null。
所以我有像这样嵌套的类:
我已经尝试创建类的实例并调用视图-出现错误, 我已经尝试在视图本身中创建类的实例-出现错误, 我已经尝试不使用PartialViews:
所以我有像这样嵌套的类:
public class Flow
{
private Action actionField
private string nameField
private bool enabledField
...
}
public class Action
{
private ActionSchedule actionScheduleField
private ActionParameter actionParameterField
private nameField
}
public class ActionSchedule
...
为“Flow”创建一个单独的创建视图
@model ProjectZeus.Models.Flow
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.TextBoxFor(model => model.name, new { @placeholder = "Flow name" })
@Html.ValidationMessageFor(model => model.name)
@Html.LabelFor(model => model.enabled)
@Html.EditorFor(model => model.enabled)
@Html.ValidationMessageFor(model => model.enabled)
@Html.Partial("FlowAction")
...
然后为每个子类创建部分视图。
@model ProjectZeus.Models.FlowAction
@Html.TextBoxFor(model => model.name, new { @placeholder = "Action name" })
...
我已经尝试创建类的实例并调用视图-出现错误, 我已经尝试在视图本身中创建类的实例-出现错误, 我已经尝试不使用PartialViews:
@Html.TextBoxFor(model => model.action.name, new { @placeholder = "Action name" })
我已经谷歌搜索了很多次,但没有成功,请求帮助!
编辑:
实现一个客户模型绑定器似乎有些过头了。这个页面描述了相同的问题,但是解决方案代码不适用于我,“当前上下文中不存在'helper'的名称”?-http://danielhalldev.wordpress.com/2013/08/23/partial-views-and-nested-mvc-model-binding/
编辑2:
我更改了模型定义以缩短长度 - 该模型实际上是从xsd自动生成的:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class D53ESBFlow
{
private D53ESBFlowAction actionField;
[Required]
private string nameField;
...
private bool enabledField;
/// <remarks/>
public D53ESBFlowAction action
{
get
{
return this.actionField;
}
set
{
this.actionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
编辑 3(提升):
看起来“binder”正在创建一个属性而不是类对象?
Action
不是嵌套类,而是Flow
类中的一个属性。 - Yair Nevet