コード例 #1
0
        private IHtmlContent CreateSearchElement(TagHelperContext context)
        {
            string value, name;

            if (typeof(BaseNamedEntity).IsAssignableFrom(ValueExpression.ModelExplorer.ModelType))
            {
                value = ((BaseNamedEntity)ValueExpression.Model)?.Name;
                name  = ValueExpression.ModelExplorer.Metadata.PropertyName + ".Name";
            }
            else
            {
                value = ValueExpression.Model?.ToString();
                name  = null;
            }

            var input = new EntitySearchTagHelper(Generator)
            {
                Type        = ViewHelpers.GetControllerFor(ValueExpression.ModelExplorer.ModelType),
                Class       = Class,
                Style       = Style,
                Value       = value,
                Name        = name,
                ViewContext = ViewContext
            };

            if (CurrentOnly)
            {
                input.FilterName  = "year";
                input.FilterValue = ViewContext.ViewBag.SelectedContestYear;
            }

            TagHelperOutput inputOutput = CreateTagHelperOutput("search");

            input.Process(context, inputOutput);

            return(inputOutput);
        }
コード例 #2
0
 public static string GetControllerFor <TEntity, TProperty>(this IHtmlHelper <TEntity> html, Expression <Func <TEntity, TProperty> > expression)
     where TEntity : BaseEntity where TProperty : BaseEntity
 {
     return(ViewHelpers.GetControllerFor(typeof(TProperty)));
 }