Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 12, 2011 04:59 AM by sudheervm
Oct 06, 2011 10:23 AM|LINK
On a controller page i am using two ActionResult functions and the same variable is being called on two different ActionResult functions, i want to take the value of the variable using viewbag as below. pleae guide what is the exact syntax.
@Html.ActionLink(ViewBag.Lang, ViewBag.Lang, "Home")
Oct 06, 2011 01:24 PM|LINK
@Html.ActionLink(ViewBag.Lang.ToString(), ViewBag.Lang.ToString(), "Home") does not work?
Oct 06, 2011 08:46 PM|LINK
ViewBag nor ViewData dont work as actionlink parameter.
another option you have is that create new property of Lang in you model,
and do like this:
i tested this and it worked.
Oct 06, 2011 08:49 PM|LINK
nevermind. this should work :
so use ViewData["Lang"] instead of ViewBag.Lang in your controller.
the reason that viewbag doesnt work while viewdata works is i think viewbag is dynamic type while viewdata is an object.
correct me if i am wrong.
Oct 07, 2011 11:29 PM|LINK
You just need to cast it, nothing else so write it:
@Html.ActionLink((string)ViewBag.Lang, (string)ViewBag.Lang, "Home")
Oct 11, 2011 01:24 AM|LINK
You are using this overload method of ActionLink():
ActionLink Method (HtmlHelper, String, String, String)
So you should change the value of the ViewBag to string. If it is still not work, please contact with me. About ActionLink Method, please check here:
Hope this helpful
Oct 12, 2011 04:59 AM|LINK
string lang = ViewBag.Lang;
@Html.ActionLink(lang, lang, "Home");