How to set Dynamic title of @Html.ActionLink from Controller?

imdadhusen picture imdadhusen · Jun 9, 2011 · Viewed 14.4k times · Source

i have

@Html.ActionLink("Remove 1034, 1035, 1036", "RemoveSelected")

Now i want to set each id from Controller

for example:

@Html.ActionLink(ViewBag.RemoveSelectedTitle, "RemoveSelected") //this is not work

// GET: /TabMaster/
        public ActionResult Index()
        {
            ViewBag.RemoveSelectedTitle = "100,101,102";
            return View(_tabmasterService.GetTabMasterList(10, 1));
        }

Answer

lancscoder picture lancscoder · Jun 9, 2011

You need to cast the RemoveSelectedTitle as a string. As your using the Viewbag this is a dynamic object and doesn't know the RemoveSelectedTitle is a string. You ActionLink should be something like:

@Html.ActionLink((string)ViewBag.RemoveSelectedTitle, "RemoveSelected")