Create custom HTML helper for this. Generate HTML markup using TagBuilder and use UrlEncode where you want. For example:
public static string SearchActionLink(this HtmlHelper html, string linkText, string actionName, object routeValues)
{
var innerHtml = html.ViewContext.HttpContext.Server.UrlEncode("....");
TagBuilder tagBuilder = new TagBuilder("a") {
InnerHtml = innerHtml;
};
var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
var url = urlHelper.Action(actionName, routeValues);
tagBuilder.MergeAttribute("href", url);
return tagBuilder.ToString(TagRenderMode.Normal);
}
UPDATED:
Something like this?:
public static string SearchActionLink(this HtmlHelper html, string linkText, System.Web.Routing.RouteValueDictionary routeValues)
{
var ref = html.ViewContext.HttpContext.Server.UrlEncode(routeValues["ref"]);
routeValues["ref"] = "_REF_";
TagBuilder tagBuilder = new TagBuilder("a") { InnerHtml = linkText; };
var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
var url = urlHelper.RouteUrl(routeValues).Replace("_REF_", ref);
tagBuilder.MergeAttribute("href", url);
return tagBuilder.ToString(TagRenderMode.Normal);
}