从枚举中填充复选框列表

时间:2015-09-08 14:32:59

标签: c# asp.net-mvc checkbox enums

我创建了一个公共枚举兴趣

require 'yaml'

namespace :db do
    def backup_prep
    @directory = File.join(Rails.root, 'db', 'backup')
    @db = YAML::load( File.open( File.join(Rails.root, 'config', 'database.yml') ) )[ Rails.env ]
    @db_params = "-u #{@db['username']} #{@db['database']}"
    @db_params = "-p#{@db['password']} #{@db_params}" unless @db['password'].blank?
  end

  desc 'Backup database by mysqldump'
  task :backup => :environment do
    backup_prep
    FileUtils.mkdir @directory unless File.exists?(@directory)
    file = File.join( @directory, "#{RAILS_ENV}_#{DateTime.now.to_s}.sql" )
    command = "mysqldump #{@db_params} | gzip > #{file}.gz" #--opt --skip-add-locks 
    puts "dumping to #{file}..."
    # p command
    exec command
  end

  desc "restore most recent mysqldump (from db/backup/*.sql.*) into the current environment's database."
  task :restore => :environment do
    unless ENV['RAILS_ENV']=='development'      
      puts "Are you sure you want to import into #{ENV['RAILS_ENV']}?! [y/N]"
      return unless STDIN.gets =~ /^y/i
    end
    backup_prep
    wildcard  = File.join( @directory, ENV['FILE'] || "#{ENV['FROM']}*.sql*" )
    puts file = `ls -t #{wildcard} | head -1`.chomp  # default to file, or most recent ENV['FROM'] or just plain most recent
    if file =~ /\.gz(ip)?$/
      command = "gunzip < #{file} | mysql #{@db_params}"
    else
      command = "mysql #{@db_params} < #{file}"
    end
    p command
    puts "please wait, this may take a minute or two..."
    exec command
  end
end

并希望在我的用户个人资料中有一个枚举列表

public enum Interests
{
    Sport,
    Party,
    Gaming   
}

我想为我的枚举值创建一个Checkbox-Form,最终应该存储在我的列表中,但是无法找到...

我希望enum中的每个Hobby拥有一个Checkbox-Field,每个选中的Checkbox都应该存储在List中。

0 个答案:

没有答案