加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 静态类型不能用作参数

发布时间:2020-12-15 03:56:55 所属栏目:百科 来源:网络整理
导读:我正在跟随MVC音乐商店教程,但是在第5部分: Part 5中,我刚刚遇到了Html Helper. 我似乎已经正确跟踪到目前为止(请纠正我,如果我错了:))但是我收到以下错误: ‘musicStoreMVC.Helpers.HtmlHelper’: static types cannot be used as parameters 这是我应用
我正在跟随MVC音乐商店教程,但是在第5部分: Part 5中,我刚刚遇到了Html Helper.

我似乎已经正确跟踪到目前为止(请纠正我,如果我错了:))但是我收到以下错误:

‘musicStoreMVC.Helpers.HtmlHelper’:
static types cannot be used as
parameters

这是我应用程序中的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace musicStoreMVC.Helpers
{
    public static class HtmlHelper
    {
        public static string Truncate(this HtmlHelper helper,string input,int length)
        {
            if (input.Length <= length)
            {
                return input;
            }
            else
            {
                return input.Substring(0,length) + "...";
            }
        }
    }
}

如果有人可以看到我做错了什么,或者如果需要更多的信息,我将不胜感激!谢谢.

解决方法

只需将静态HtmlHelper类重命名为HtmlHelperExtensions.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读