Я использовалКак я могу назвать Url.Action из класса HtmlHelper?
Url.Action("actionFoo", "controllerBar")
в моих взглядах (ASPX). Но теперь я реорганизую часть моей разметки на созданный HtmlHelper.
Проблема: у меня нет подходящих пространств имен или у View есть ссылка на объект по умолчанию, о которой я не знаю. Точка - компилятор не может найти Url.Action.
Для простоты ради здесь является то, что я пытаюсь сделать ...
public static MvcHtmlString RenderActionButtons(this HtmlHelper helper, string actionName, string controllerName)
{
TagBuilder customActionButtonTagBuilder = new TagBuilder("a");
customActionButtonTagBuilder.Attributes.Add(new KeyValuePair<string, string>("href", Url.Action(actionName, controllerName)));
customActionButtonTagBuilder.InnerHtml = "foo";
customActionButtonTagBuilder.AddCssClass("custom-action-button");
return MvcHtmlString.Create(customActionButtonTagBuilder.ToString(TagRenderMode.Normal));
}
Как указать свой код для надлежащего использования Url.Action?
возможно дубликат [Сформировать URL в помощнике HTML] (HTTP: //stackoverflow.com/questions/1443647/generate-url-in-html-helper) – Marijn 2014-05-30 14:03:56