1 Star 0 Fork 0

richieyangs / TypedMvcActionHelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TypedActionLinkGenerator.cs 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
RichieZhang 提交于 2016-05-31 16:56 . typed action helper
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace TypedMvcActionHelper
{
public static class TypedActionLinkGenerator
{
public static MvcHtmlString GenerateActionLink<TController>(this HtmlHelper htmlHelper, string linkText, Expression<Func<TController, ActionResult>> expression, object htmlAttributes)
where TController : ControllerBase
{
var definition = MvcInvocationDefinition.Create(expression);
return htmlHelper.ActionLink(linkText, definition.ActionName, definition.ControllerName, definition.RouteValues, ToDictionary(htmlAttributes));
}
private static IDictionary<string,object> ToDictionary(object htmlAttributes)
{
var dictionary=new Dictionary<string,object>();
if (htmlAttributes != null)
{
foreach (var attribute in htmlAttributes.GetType().GetProperties())
{
dictionary.Add(attribute.Name, attribute.GetValue(htmlAttributes));
}
}
return dictionary;
}
}
}
C#
1
https://gitee.com/richieyangs/TypedMvcActionHelper.git
git@gitee.com:richieyangs/TypedMvcActionHelper.git
richieyangs
TypedMvcActionHelper
TypedMvcActionHelper
master

搜索帮助