【问题标题】:how to display dynamic text to @Html.Lable from Controller如何从控制器向@Html.Label 显示动态文本
【发布时间】:2011-06-10 05:19:47
【问题描述】:

我有

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

现在在 Index.cshtml 中

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

但这会给我一个错误。

编译器错误消息:CS1973:“System.Web.Mvc.HtmlHelper”没有名为“Label”的适用方法,但似乎具有该名称的扩展方法。扩展方法不能动态调度。考虑强制转换动态参数或调用扩展方法而不使用扩展方法语法。

【问题讨论】:

  • 编辑问题并向其添加错误消息,而不是评论。

标签: asp.net asp.net-mvc


【解决方案1】:
@Html.Label("Set from controller", Convert.ToString((int)ViewBag.TotalRecords))

【讨论】:

    猜你喜欢
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多