mvc5 html5,MVC5 Razor html.dropdownlist用于在值位于数组中时选择的设置

我正在使用C#和.NET Framework 4.6.1开发ASP.NET MVC 5应用程序。

我有这个View:

@model MyProject.Web.API.Models.AggregationLevelConfViewModel

[...]

@Html.DropDownListFor(m => m.Configurations[0].HelperCodeType, (SelectList)Model.HelperCodeTypeItems, new { id = "Configurations[0].HelperCodeType" })

该ViewModel是:

public class AggregationLevelConfViewModel

{

private readonly List codeTypes;

private readonly List helperCodeTypes;

public IEnumerable CodeTypeItems

{

get { return new SelectList(codeTypes, "Id", "Name"); }

}

public IEnumerable HelperCodeTypeItems

{

get { return new SelectList(helperCodeTypes, "Id", "Name"); }

}

public int ProductionOrderId { get; set; }

public string ProductionOrderName { get; set; }

public IList Configurations { get; set; }

public AggregationLevelConfViewModel()

{

// Load CodeTypes to show it as a DropDownList

byte[] values = (byte[])Enum.GetValues(typeof(CodeTypes));

codeTypes = new List();

helperCodeTypes = new List();

for (int i = 0; i < values.Length; i++)

{

GenericIdNameType cType = new GenericIdNameType()

{

Id = values[i].ToString(),

Name = EnumHelper.GetDescription((CodeTypes)values[i])

};

if (((CodeTypes)values[i]) != CodeTypes.NotUsed)

codeTypes.Add(cType);

helperCodeTypes.Add(cType);

}

}

}

并且Models.AggregationLevelConfiguration是:

public class AggregationLevelConfiguration

{

public byte AggregationLevelConfigurationId { get; set; }

public int ProductionOrderId { get; set; }

public string Name { get; set; }

public byte CodeType { get; set; }

public byte HelperCodeType { get; set; }

public int PkgRatio { get; set; }

public int RemainingCodes { get; set; }

}

我需要在这些属性中设置选定的值:

public IEnumerable CodeTypeItems

{

get { return new SelectList(codeTypes, "Id", "Name"); }

}

public IEnumerable HelperCodeTypeItems

{

get { return new SelectList(helperCodeTypes, "Id", "Name"); }

}

但是我无法设置它,new SelectList(codeTypes, "Id", "Name");或者new

SelectList(helperCodeTypes, "Id", "Name");因为选择的值在Configurations数组中:fields

AggregationLevelConfiguration.CodeType和AggregationLevelConfiguration.HelperCodeType。

我想我必须在“视图”中设置选定的值,但是我不知道该怎么做。

如何设置选择的值?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值