Asp.net-mvc – how to display dynamic text to @Html.Lable from Controller

asp.netasp.net-mvc

I have

public ActionResult Index()
        {
            ViewBag.TotalRecords = _tabmasterService.Count();
            return View(_tabmasterService.GetTabMasterList(10, 1));
        }

now in Index.cshtml

 @Html.Label("Set from controller", Convert.ToString(ViewBag.TotalRecords))

but this will gives me an error.

Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Label' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

Best Answer

@Html.Label("Set from controller", Convert.ToString((int)ViewBag.TotalRecords))
Related Topic