Asp.net Mvc - Why Is ViewContext.ViewName Not Available
Jan 11, 2010
I read several examples on the web which use the following code:
Private Function SomeFunction(ByVal htmlhelper As HtmlHelper) As String
Dim controller As Controller = htmlhelper.ViewContext.Controller
If controller IsNot Nothing Then
[Code].....
View 1 Replies
Mar 30, 2011
i have worked on a culture switch control and i need to modify the ViewContext.RouteData("culture") to check if the view exists anyway when i do the following
Dim routeData As RouteData = ViewContext.RouteData
routeData.Values.Remove("culture")
routeData.Values.Add("culture", cultureValue)
then the original ViewContext.RouteData is changed when i change the routeData.I have tested to do the following to but no success
Dim tempViewContext As New ViewContext(ViewContext.Controller.ControllerContext, ViewContext.View, ViewContext.ViewData, ViewContext.TempData, ViewContext.Writer)
Dim routeData As RouteData = tempViewContext.RouteData
routeData.Values.Remove("culture")
routeData.Values.Add("culture", cultureValue)
how to copy the ViewContext to a temporary object and changing the values without changing the original ViewContext values?
Edit: The only way i know work is to change the routeData then check if it exists and after it change the routeData back to the original culture... was hopping there were a another way but it works for know.
View 1 Replies