C# 对象支持的MVC5 HTML输入

C# 对象支持的MVC5 HTML输入,c#,.net,entity-framework,razor,asp.net-mvc-5,C#,.net,Entity Framework,Razor,Asp.net Mvc 5,Tl;Dr我找不到正确的命名约定来获取要填充的属性对象。 所以我有一个项目,我正在工作,用户将需要能够创建动态html输入。我已经为此创建了一个模型,如下所示 public class Property { public String name { get; set; } public List<String> dataTypes { get; set; } public String dataType { get; set; } publi

Tl;Dr我找不到正确的命名约定来获取要填充的属性对象。

所以我有一个项目,我正在工作,用户将需要能够创建动态html输入。我已经为此创建了一个模型,如下所示

 public class Property
{

    public String name { get; set; }

    public List<String> dataTypes { get; set; }

    public String dataType { get; set; }

    public Guid PropertyID { get; set; }

    public virtual Range valueRange { get; set; }

    public int length { get; set; }

    public String label { get; set; }

    public String format { get; set; }

    public String cssClasses { get; set; }

    public Dictionary<string, string> selectOptions { get; set; }

    public dynamic value { get; set; }
}
   public Property(String name = "", dynamic value = null, List<String> dataTypes = null, Range valueRange = null, int length = 0, String format = "", String label = "")
    {
        this.name = name;
        this.valueRange = valueRange == null ? new Range() : valueRange;
        this.length = length;
        this.format = format;
        this.label = label == "" ? name : label;

        this.dataTypes = dataTypes == null ? new List<String> {
            GlobalConstants.COMMA,
            GlobalConstants.TEXT,
            GlobalConstants.NUMBER,
            GlobalConstants.TEXTAREA,
            GlobalConstants.SELECT,
            GlobalConstants.DATEPICKER,
            GlobalConstants.USERPICKER,
            GlobalConstants.DOCUMENT } : dataTypes;
        this.value = null;



    }

我假设这应该是
公共字典DefaultProperties{get;set;}
?是的,修复了它。很好看。我想应该是
公共字典DefaultProperties{get;set;}
?是的,修复了它。很好看。
public class Template
{
    public Dictionary<string,Property> DefaultProperties {get;set;}
    public Template()
    {
    this.DefaultProperties = new Dictionary<string, Property>
        {
                {"name", new Property{ name="name", dataType= GlobalConstants.TEXT , label="Template Name", } },
                {"parties", new Property{ name="parties", dataType= GlobalConstants.TEXT , label="Parties Filing the Grievance" } },
                {"dateFiled", new Property{ name="dateFiled", dataType=  GlobalConstants.TEXT , cssClasses ="datepicker", label="Date Filed" } },
                {"reviewerGroup", new Property{ name="reviewerGroup", dataType= GlobalConstants.USERPICKER , cssClasses ="selectUsers", label="Reviewer Group" } },
                {"approverGroup", new Property{ name="approverGroup", dataType= GlobalConstants.USERPICKER , cssClasses ="selectUsers", label="Approver Group" } },
                {"governingAgreements", new Property{ name="governingAgreement", dataType= GlobalConstants.COMMA , label="Governing Agreement Sections" } },
                {"department", new Property{ name="department", dataType= GlobalConstants.TEXT , label="Department Where Grievance was filed" } },
                {"politicalJudgement", new Property{ name="politicalJudgement", dataType= GlobalConstants.SELECT , label="Political Impact", selectOptions = new Dictionary<string, string> { { "high", "High" }, { "medium", "Medium" },{ "low", "Low" } } } },
                {"monetaryJudgement", new Property{ name="monetaryJudgement", dataType= GlobalConstants.SELECT , label="Monetary Impact", selectOptions = new Dictionary<string, string> { { "high", "High" }, { "medium", "Medium" },{ "low", "Low" } } } },
                {"processJudgement", new Property{ name="processImpactJudgement", dataType= GlobalConstants.SELECT , label="Process Impact", selectOptions = new Dictionary<string, string> { { "high", "High" }, { "medium", "Medium" },{ "low", "Low" } } } }
        };
    }
}
@foreach (var property in Model.DefaultProperties)
    {
        <div class="form-group">
            @MyHelpers.generateProperty(property.Value, Html, true, false, "Template.DefaultProperties")
        </div>
    }
@helper buildInput(FBT_GRASP.Models.GrievanceProperty property, String type = "text", String classes = "", Dictionary<string, string> extraProperties = null, string parentObject = "")
{
<input data-field="@Json.Encode(property)"
       name="@(parentObject+"['"+property.name+"']")"
       id="@property.name"
       type="@type"
       value="@property.value"
           class="form-control @if (classes != "") {<text>@classes</text> }     @{if     (property.cssClasses != null) { <text> @property.cssClasses</text> } }"
       @{if (extraProperties != null) {
               foreach (KeyValuePair<string, string> kv in extraProperties) {
                   <text>data-@(kv.Key)="@(kv.Value)"</text>
               }
           }
       }
       @{if (property.placeholders.ContainsKey(property.dataType)) { <text> placeholder="@property.placeholders[property.dataType].placeholder" </text> } }
       @{if (property.placeholders.ContainsKey(property.dataType)) { <text> pattern="@property.placeholders[property.dataType].pattern" </text> } } />
}
<input name="Template.DefaultProperties['name']" id="name" class="form-control valid" placeholder="Free form text field" pattern="">
    [HttpPost]
    public ActionResult Create(Template Template)
    {
        db.Templates.Add(template);
        db.SaveChanges();
        return Redirect("/template/edit/" + template.templateID);
    }