简体   繁体   English

IDictionary MVC中的字典

[英]Dictionary inside IDictionary MVC

I had to alter a radio button to include a new value. 我不得不更改一个单选按钮以包括一个新值。 To do this I had to put a Dictionary inside an IDictionary. 为此,我必须将字典放入IDictionary中。 The key pulls in great for the IDictionary but the Dictionary int and string don't pull in at all. 关键字对于IDictionary来说是很好的选择,但是Dictionary int和string根本没有采用。 I believe it's my front end code. 我相信这是我的前端代码。 Can anyone see what I am doing wrong and provide an example on how to fix? 谁能看到我在做什么错,并提供有关如何修复的示例?

Action Parameter in Controller 控制器中的动作参数

IDictionary<String, Dictionary<int, String>>

View 视图

<fieldset>
<legend class="sr-only">Actions</legend>
<input type="hidden" name="customerId" value="@account.CustomerId" />
<input type="hidden" name="yearSetupId" value="@account.YearId" />
<label class="radio-inline"><input type="radio" name="accountActions[@(account.CustomerId)].Key[@(account.Id)].Value" value="" checked="checked">Do nothing</label>
@{
     var possibleActions = account.Balance < 0 ? new[] { 
     BalanceAdjustmentType.Zeroed, BalanceAdjustmentType.Issued }
                                    : new[] { BalanceAdjustmentType.Under, BalanceAdjustmentType.Sent };
                                }
@foreach (var action in possibleActions)
                                {
<label class="radio-inline"><input type="radio" name="accountActions[@(account.CustomerId)].Key[@(account.YearId)].Value" value="@action.BalanceId">@action.Text</label>
                                }
</fieldset>

I didn't understand your controller parameter means actually. 我不明白您的控制器参数的实际含义。 But I supposed the "accountActions" in your view was the variable of your "controller parameter". 但是我认为您认为“ accountActions”是“控制器参数”的变量。 If so, then your could access the nested dict value by accountActions[Key][InnerKey]. 如果是这样,那么您可以通过accountActions [Key] [InnerKey]访问嵌套的dict值。

<fieldset>
    <legend class="sr-only">Actions</legend>
    <input type="hidden" name="customerId" value="@account.CustomerId" />
    <input type="hidden" name="yearSetupId" value="@account.YearId" />
    <label class="radio-inline">
        <input type="radio" name="@accountActions[account.CustomerId][account.Id]" value="" checked="checked">
        Do nothing
    </label>    

    @{ 
        var possibleActions = account.Balance < 0 
        ? new[] { BalanceAdjustmentType.Zeroed, BalanceAdjustmentType.Issued } 
        : new[] { BalanceAdjustmentType.Under, BalanceAdjustmentType.Sent }; 
    } 

    @foreach (var action in possibleActions) { 
        <label class="radio-inline">
            <input type="radio" name="@accountActions[account.CustomerId][account.YearId]" value="@action.BalanceId">
            @action.Text
        </label>
    }
</fieldset>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM