Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何发布列表<;T>;在ASP.NETMVC中,模型是否工作?_C#_Asp.net_Asp.net Mvc_Http_Asp.net Mvc 4 - Fatal编程技术网

C# 如何发布列表<;T>;在ASP.NETMVC中,模型是否工作?

C# 如何发布列表<;T>;在ASP.NETMVC中,模型是否工作?,c#,asp.net,asp.net-mvc,http,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Http,Asp.net Mvc 4,我有下面的类,我想以表单的形式显示,并允许它发布到运行在不同服务器上的ASP.NET MVC 我的所有属性都正常工作,但我无法使列表正常工作 public class TokenCreateConfirm { public string UIDPName { get; set; } public TokenCreateConfirm() { Attributes = new List<Attr>(); } public stri

我有下面的类,我想以表单的形式显示,并允许它发布到运行在不同服务器上的ASP.NET MVC

我的所有属性都正常工作,但我无法使列表正常工作

public class TokenCreateConfirm
{
    public string UIDPName { get; set; }

    public TokenCreateConfirm()
    {
       Attributes = new List<Attr>();
    }
    public string ProverURL { get; set; }

   public List<Attr> Attributes { get; set; }
}
公共类令牌创建确认
{
公共字符串UIDPName{get;set;}
公共令牌createconfirm()
{
属性=新列表();
}
公共字符串ProverURL{get;set;}
公共列表属性{get;set;}
}

我应该如何以某种形式呈现
属性
列表变量,使其正确发布到ASP.NET MVC?

如果要编辑现有属性列表,请首先为
Attr
类创建
EditorTemplate
共享/EditorTemplates/Attr.cshtml

@model MyNamespace.Attr

@Html.TextBoxFor(model => model.Prop1)

// Add whatever fields from Attr, you can also you drop down lists or checkboxes
然后在主视图中,您可以这样使用它:

@model MyMainNamespace.tokenCreateConfirm

@Html.EditorFor(model => model.UIDPName)

// Display or edit other simple properties as you like

@Html.EditorFor(model => model.Attributes)
视图引擎将在
Shared/EditorTemplates
文件夹中查找名为
Attr.cshtml
的模板,然后将其应用于列表的每个元素。通过这种方式,在生成html时正确命名,并且在提交表单时返回值:

[HttpPost]
public ActionResult SaveInput(TokenCreateConfirm token)
{
    var attributes = token.Attributes;
    // ...
}

我想你在找这样的东西():

for(int i=0;i model.Attributes[i].PropertyName)
...
...
...
}

到目前为止您尝试了什么?您是否正在使用
编辑模板
?目标操作是否需要类型为
TokenCreateConfirm
的参数?我不知道editorTemplates将如何呈现列表,或者生成的HTML表单输出将是什么。到目前为止,我认为我需要序列化类型,并将其保存为隐藏字段中的JSON文本。注意:我不希望允许用户编辑列表,这是只读的,用于所有目的和目的,尽管我在学术上对读/写方法
@Html.EditorFor(x=>x.Attributes)感兴趣
除非明确定义特定模板,否则不会输出任何内容。@makerofthings7属性在html dom中的呈现方式。。我是说收音机,下拉菜单还是别的?
for(int i=0;i<Model.Attributes.Count;i++)
{
    @Html.TextBoxFor(model => model.Attributes[i].PropertyName)
    ...
    ...
    ...
}