Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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));
        }
like image 886
imdadhusen Avatar asked Jun 09 '11 12:06

imdadhusen


2 Answers

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")
like image 153
lancscoder Avatar answered Sep 22 '22 13:09

lancscoder


I was trying to concatenate some hard coded text, and an int from the ViewBag, and found that this syntax worked:

@Html.ActionLink((string)("Remove Selected - # " + ViewBag.RemoveSelectedNumber.ToString()), "RemoveSelected")
like image 28
Yves Rochon Avatar answered Sep 18 '22 13:09

Yves Rochon