更新时间:2023-01-07 08:46:02
如果您对RouteLink包装比有问题的简单的解决方案。
例如,我有一个包装方法RouteLinkEx:
If you have a wrapper over RouteLink than there is an easy solution of the problem. For example, I had a wrapper method RouteLinkEx:
public static string RouteLinkEx(this HtmlHelper helper,string text,string routeName,RouteValueDictionary rvd,object htmlAttributes)
{
UrlHelper uh = new UrlHelper(helper.ViewContext.RequestContext,helper.RouteCollection);
// Add trailing slash to the url of the link
string url = uh.RouteUrl(routeName,rvd) + "/";
TagBuilder builder = new TagBuilder("a")
{
InnerHtml = !string.IsNullOrEmpty(text) ? HttpUtility.HtmlEncode(text) : string.Empty
};
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
builder.MergeAttribute("href",url);
return builder.ToString(TagRenderMode.Normal);
//---
}
当你看到我使用的参数首先生成URL。然后,我添加/在URL的结尾。然后我生成使用这些URL链接完成
As you see I used parameters to generate URL first. Then I added "/" at the end of the URL. and then I generated complete link using those URL.