C# Webgrid中的Html.ActionLink返回空字符串
我正在尝试向webgrid列添加ActionLink,但遇到了问题 如果我像这样添加操作链接,它会工作并链接到主UserDetails页面:C# Webgrid中的Html.ActionLink返回空字符串,c#,asp.net-mvc,actionlink,C#,Asp.net Mvc,Actionlink,我正在尝试向webgrid列添加ActionLink,但遇到了问题 如果我像这样添加操作链接,它会工作并链接到主UserDetails页面: grid.Column(header: "", format: (item) => Html.ActionLink("Details", "UserDetails", "Admin")) 但是,如果我尝试传入网格项的用户,它将返回空字符串 这: 结果如下: <a href=""> 我的这个视图和网格模型是 List<UserIn
grid.Column(header: "", format: (item) => Html.ActionLink("Details", "UserDetails", "Admin"))
但是,如果我尝试传入网格项的用户,它将返回空字符串
这:
结果如下:
<a href="">
我的这个视图和网格模型是
List<UserInfo>
列表
其中UserInfo有“user”和“activedate”
我还是MVC新手,所以我希望我忽略了一些愚蠢的事情
谢谢。ActionLink使用您的路由来确定是否可以构建链接。如果没有,它有时什么也不返回。从Reflector(下面)中,注意htmlHelper.RouteCollection。检查您的global.asax(也许可以使用您想要构建的URL运行您的站点),以确保路由表将路由该URL
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
if (string.IsNullOrEmpty(linkText))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null, actionName, controllerName, routeValues, htmlAttributes));
}
public static MvcHtmlString ActionLink(此HtmlHelper HtmlHelper、字符串链接文本、字符串actionName、字符串控制器名称、RouteValueDictionary routeValues、IDictionary htmlAttributes)
{
if(string.IsNullOrEmpty(linkText))
{
抛出新ArgumentException(MvcResources.Common_NullOrEmpty,“linkText”);
}
返回MvcHtmlString.Create(HtmlHelper.GenerateLink(HtmlHelper.ViewContext.RequestContext,HtmlHelper.RouteCollection,linkText,null,actionName,controllerName,RouteValue,htmlAttributes));
}
谢谢,就这样。我将路由添加到了我的Global.asax中,并纠正了我如何处理UserDetails模型,并且它工作正常。
public ActionResult UserDetails(string username)
{
return View();
}
List<UserInfo>
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
if (string.IsNullOrEmpty(linkText))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null, actionName, controllerName, routeValues, htmlAttributes));
}