将复选框值插入数据库,用逗号分隔

时间:2015-10-05 14:13:36

标签: c# asp.net-mvc model-view-controller checkbox

在我的.cshtml文件中,我有一个带有复选框的表单:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN; // return 0.01f; would work same 
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

如何在逗号分隔的单个数据库列中插入这些复选框的值?

(我是一个全新的C#学习者)

这是我在codebehind中的插入内容:

nil

1 个答案:

答案 0 :(得分:0)

您需要一个视图模型。然后,您可以映射到列表或从列表映射到字符串:

public class HGProgramViewModel
{
    // other HGProgram properties you want to edit

    public string Child1GiftTypeNeed { get; set; }

    public List<string> Child1GiftTypeNeedList
    {
        get
        {
            !string.IsNullOrWhiteSpace(Child1GiftTypeNeed)
                ? Child1GiftTypeNeed.Split(',').ToList()
                : new List<string>();
        }
        set
        {
            Child1GiftTypeNeed = value != null
                ? string.Join(",", value)
                : null;
        }
    }
}

然后,在您的视图中,您只需要为字段Child1GiftTypeNeedList[]命名即可。无论如何,索引语法[]都是必需的,就像现在的方式一样,只会发布一个复选框值(页面上最后一个复选框)。

相关问题