我在做我的MVC应用程序。我通过实体框架将它连接到我的数据库。在我的控制器我会像这样的观点:从数据库中读取MVC数据
public ActionResult MyMarks()
{
ClassDeclarationsDBEntities1 entities=new ClassDeclarationsDBEntities1();
return View(entities.Users.ToList());
}
我的看法是:
@using ClassDeclarationsThsesis.Models
@using Microsoft.AspNet.Identity
@{
ViewBag.Title = "My Marks";
}
<div>
<h4>Account information</h4>
<hr/>
<dl class="dl-horizontal">
<dt>Name</dt>
<dd>Student's name</dd>
<dd></dd>
<dt>Surname</dt>
<dd>Student's surname</dd>
<dt>Email</dt>
<dd>
@HttpContext.Current.User.Identity.Name
</dd>
</dl>
</div>
如何用实际数据代替学生的名字和姓氏从传入构造实体?鉴于
您推荐从数据库构建学生模型,然后传递此模型以查看并在视图内呈现所需的字段。 – tym32167
你应该阅读关于ASP.NET MVC的基础知识。例如如何传递模型来查看。 –