【问题标题】:How do i Show ViewBag in html我如何在 html 中显示 ViewBag
【发布时间】:2015-09-21 05:53:11
【问题描述】:

我试图展示我的产品的一些细节 (shoes=zapatillas) 在 Visual Studio 2013 c# mvc 上 好的,让我们开始使用代码... 这是我在 HomeController 上的索引网页的一部分 http://pastebin.com/VRMb85Qf

这是我的 Producto.cs http://pastebin.com/a2H1ifZT

这是我的 index.cshtml,我想在其中放置一些详细信息,我的问题是,如何在 PRICE、MODEL、INFO 所在的 html 中调用我的 sql 详细信息 看看@zap 失败代码,是这样的吗? 开

    ON THE TOP PAGE @using La_esquina_del_calzado1.Models;
in the body...
@foreach (Producto zap in ViewBag.lstProductos)
    {           @zap.getid()
                @zap.getmodelo()
                @zap.getcolor()
    }

            <div class="col-sm-4 col-lg-4 col-md-4">
                <div class="thumbnail">
                    <img src="http://placehold.it/320x150" alt="">
                    <div class="caption">
                        <h4 class="pull-right">PRICE</h4>
                        <h4>
                            <a href="#">MODEL</a>
                        </h4>
                        <p>INFO</p>

                    </div>
                </div>
            </div>

【问题讨论】:

  • 您到底想做什么?你想在标签中显示 ZAP 的数据吗?
  • 是的!我想这样做,它会返回 sql 数据库表对吗?
  • 您可以使用@Html.Raw 来显示任何数据

标签: c# html foreach viewbag


【解决方案1】:

我认为您必须循环播放 ViewBag.Productos 而不是 ViewBag.lstProductos

【讨论】:

  • 我试过这种方式回家pastebin.com/x4Uj6pQa & cshtml ------>pastebin.com/Kv7bKx9c 我无法在价格模型信息中连接它
  • 你这样尝试是什么意思?该链接只是将我重定向到您的 HomeController 代码。你到底想做什么?
  • 我想在价格、型号和信息字段上显示我的 SQL 服务器表,如果我不清楚,请见谅
  • 我想你需要的是 lstProductos 列表? ViewBag.Productos 有什么好处?
  • 仍然无法正常工作 ;(,我不知道如何调用 @cal 项目
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多