我很好奇如何调用LinkExtensions.ActionLink Method (HtmlHelper, String, String)HtmlHelper.ActionLink()
中描述的Method以下是我的Controller,在一个空的 MVC 项目中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace TempMVC.Controllers
{
public class DataController : Controller
{
public ActionResult Index()
{
HtmlHelper.GenerateLink(
RequestContext requestContext,
RouteCollection routeCollection,
string linkText,
string routeName,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, object> htmlAttributes
); //OK
HtmlHelper.GenerateRouteLink(
RequestContext requestContext,
RouteCollection routeCollection,
string linkText,
string routeName,
RouteValueDictionary routeValues,
IDictionary<string, object> htmlAttributes
); //OK
HtmlHelper.ActionLink(string linkText, string actionName); //Error
return View();
}
}
}
虽然我可以使用HtmlHelper.GenerateLink()
和HtmlHelper.GenerateRouteLink()
方法,但当我尝试使用 HtmlHelper.ActionLink() 时出现以下错误:
The type name 'ActionLink' does not exist in the type 'System.Web.Mvc.HtmlHelper'
请注意,我已System.Web.Mvc.Html
在顶部声明,并且我看到它在我的Web.config文件中列出。
我可以在控制器中使用 HtmlHelper.ActionLink()方法吗?