Skip to content

Instantly share code, notes, and snippets.

@akhuang
akhuang / EnumToSelectList
Created August 24, 2013 00:25
Create dropdownlist from an enum
public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
where TEnum : struct, IComparable, IFormattable, IConvertible
{
var values = from TEnum e in Enum.GetValues(typeof(TEnum))
select new { Id = e, Name = e.ToString() };
return new SelectList(values, "Id", "Name", enumObj);
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.ViewModels
{
public class ArticleEditViewModel
public static class HtmlExtensions
{
public static MvcHtmlString ValidatedEditorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
if (htmlHelper.ViewData.ModelMetadata.ModelType == null)
{
return new MvcHtmlString(String.Empty);
}
TagBuilder tagBuilder = new TagBuilder("input");
@akhuang
akhuang / SimpleInstaller
Created June 25, 2013 13:12
Simple Installer use Wix toolset 3.8
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SimpleInstaller" Language="1033" Version="1.0.0.0" Manufacturer="MS" UpgradeCode="254afadb-8ed5-48e1-809f-f769cd030828">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SimpleInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
@akhuang
akhuang / Async.cs
Created September 6, 2012 04:31 — forked from SamSaffron/Async.cs
Async class for threading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using System.Diagnostics;
using System.Text;
namespace StackOverflow.Helpers