Search code examples
asp.netasp.net-mvcdynamicviewbaghtml.actionlink

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));
        }

Solution

  • 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")