ASP.NET MVC: obtenga ViewContext del método Helper
-
21-09-2019 - |
Pregunta
Me gustaría crear un método de ayudante estático que pueda llamar desde una vista.
¿Es posible que un método auxiliar tenga acceso al ViewContext actual sin necesidad de pasar explícitamente el ViewContext al método como parámetro?
Algo como httpcontext.current excepto para ViewContext.
Solución
public static class XTenshuns
{
public static string MyHtmlHelper(this HtmlHelper helper)
{
// it's right here -> helper.ViewContext
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow