带有非活动项的ASP.net MVC下拉列表

时间:2018-04-13 09:56:18

标签: c# asp.net-mvc html.dropdownlistfor

我的申请有问题。 我有一张桌子"文件"女巫与一个名为" Transactioncodes"的表有关系。

public class File
    {
        [Display(Name = "EcommerceFile_Id", ResourceType = typeof(Resources.ModelResources))]
        public int Id { get; set; }

        [Display(Name = "EcommerceFile_FileNumber", ResourceType = typeof(Resources.ModelResources))]
        public string FileNumber { get; set; }

        [Display(Name = "EcommerceFile_TransactionCode", ResourceType = typeof(Resources.ModelResources))]
        public int? TransactionCodeId { get; set; }
        public virtual TransactionCode TransactionCode { get; set; }

        ....
    }

public class TransactionCode
    {

        [Display(Name = "TransactionCode_Id", ResourceType = typeof(Resources.ModelResources))]
        public int Id { get; set; }

        [Display(Name = "TransactionCode_Name", ResourceType = typeof(Resources.ModelResources))]
        public string Name { get; set; }

        [Display(Name = "TransactionCode_Active", ResourceType = typeof(Resources.ModelResources))]
        public bool Active { get; set; }

    }

创建文件时,用户应为此文件选择一个事务代码。当然这不是问题。 然后,当用户打开文件信息时,应显示所有内容,并且还应该可以编辑信息。

但管理员应该可以停用事务代码(还可以添加新的事务代码)。停用的交易代码不会显示在下拉列表中,因此无法再选择它们(这正是我的意图)。

@Html.DropDownListFor(model => model.TransactionCodeId, new SelectList(ViewBag.transactioncodes, "Id", "Name", Model.TransactionCodeId), "", ViewBag.disableControls == true ? (object)new { disabled = "disabled", @class = "form-control" } : new { @class = "form-control" })

但问题是,当打开现有文件(具有已停用的事务代码)时,事务代码字段为空(因为该值在下拉列表中不可用,因为它处于非活动状态)。

我希望这边的人有类似的问题并知道解决问题的方法。

请指教。

0 个答案:

没有答案