コード例 #1
0
        public static MvcHtmlString ActionLink <TController>(this HtmlHelper helper, Expression <Action <TController> > action) where TController : Controller
        {
            var actionName     = ((MethodCallExpression)action.Body).Method.Name;
            var controllerName = action.Parameters[0].Type.Name.Replace("Controller", "");
            var mvcHtmlString  = helper.ActionLink(action, HtmlHelperExtensionForResources.ResourceFor(typeof(CommandResource), controllerName + "_" + actionName));

            return(mvcHtmlString);
        }
コード例 #2
0
        public static MvcHtmlString DropDownListFor <TItem, TEnum>(
            this HtmlHelper <TItem> htmlHelper, Expression <Func <TItem, TEnum> > expression)
        {
            ModelMetadata       metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            IEnumerable <TEnum> values   = Enum.GetValues(typeof(TEnum)).Cast <TEnum>();

            IEnumerable <SelectListItem> items =
                values.Select(value =>
            {
                string resourceFor = HtmlHelperExtensionForResources.ResourceFor(typeof(EntityResource), typeof(TEnum).Name + "_" + value.ToString());
                return(new SelectListItem {
                    Selected = value.Equals(metadata.Model), Text = resourceFor, Value = value.ToString()
                });
            });

            return(htmlHelper.DropDownListFor(expression, items));
        }