必须从数据库中检索列表 [英] must retrieve the list from the database

查看:56
本文介绍了必须从数据库中检索列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从数据库中获取一些内容并加以展示,这就是我本应显示的两个段落的方式.

it is such that I have to get something out of my content from the database and shown off, this is how I have two paragraphs which I should have shown up.

在我的模型-> undervisning.cs

public class Undervisning
{
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int Hours { get; set; }
    public string Text { get; set; }
}

在我的控制器-> undervisningcontroller.cs

public ActionResult Index()
{
    DatabaseClasseDataContext db = new DatabaseClasseDataContext();

    Undervisning newundervisning = new Undervisning();
    newundervisning.Name = db.Packages.ToList().ToString();

    return View(newundervisning);
}

我必须将其显示在此处 index.cshtml

It is such that I have to have it to be shown here index.cshtml

<div class="col-md-6 col-sm-6">
    <div class="plan">
      <h3>Enterprise<span>$59</span></h3>
       <p>Test</p>
    </div>
</div>

问题是,我坚持如何从列表中提取内容并将其放置在应有的位置,因为我说过,我不得不一次又一次使用.cshtml 2中的内容,或者随着时间的流逝而不断使用.

the problem is such that I stuck to how to pull content from the list and be where it should be, as I said I have to use what we have in .cshtml 2 once and maybe more with time.

推荐答案

undervisningcontroller.cs:

undervisningcontroller.cs:

public ActionResult Index()
    {

        DatabaseClasseDataContext db = new DatabaseClasseDataContext();
        var model=db.Packages.ToList();

        return View(model);
    }
}

index.cshtml:

index.cshtml:

   @foreach(var u in Model)
    {
    <div class="col-md-6 col-sm-6">
        <div class="plan">
          <h3>@u.Name<span>$@u.Price</span></h3>
           <p>@u.Text</p>
        </div>
    </div>
    }

这篇关于必须从数据库中检索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆