I am using ASP.NET MVC 3, with the Razor engine. I have a partial view that contains one line:
@Html.ActionLink(ViewData["UserNameIfLoggedIn"], "Index", "Home")
This partial view is rendered in my _Layout.cshtml view. The snippet that calls the controller/action is this:
@{Html.RenderAction("UserLoggedIn", "User");}
I get a compilation error, stating:
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, object)' has some invalid arguments
I have made a similar call (same amount of arguments and same parameter datatypes) in another MVC application (a tutorial) and it executed just fine. What could be causing this?? Why is this not working now?
I know this is probably an extremely rookie MVC question, but I cannot figure this one out.
EDIT: The solution is this:
@Html.ActionLink(ViewData["UserNameIfLoggedIn"].ToString(), "Index", "Home")
I just needed to call the ToString() method to get the parameter as a string.
"Some Text Here" + ViewData["key"], in which case I'm guessingViewData["key"]was cast to a string. Good catch.