所以我正在做一个项目,我必须在MVC框架环境中显示数据,我的老师希望我们利用SQL Server。
我目前正在尝试将特定国家/地区的标志绑定到其ID(该标志是varbinary,并且是我在数据库中提供的文件名)。
下面是我要实现的目标的一个示例:
显示国家列表时,我希望我放入数据库中的关联标志显示在该国家旁边。示例:荷兰的ID号为1,德国的标识号为2,比利时的标识号为3。我希望将它们各自的标志显示在旁边。
但是我目前被困住了。我将提供一些代码以使其更加清晰。
控制器代码
public actionResult Details(int id)
{
//make new instance of class,proceed to connect queries to the instances and return a view
NationPlayerList nationPlayerList = new NationPlayerList();
nationPlayerList.Players = db.Players.Where(p => p.Nation_ID == id).ToList();
nationPlayerList.Nation = db.Nations.Single(n => n.Nation_ID == id);
return View(nationPlayerList);
}
详细信息HTML
<dd>
<img src=@Url.Content("../../flags/" + Model.Nation.flag.ToList()) />
</dd>
如果需要更多信息,我会很乐意提供。我是MVC的新手,所以我可能会偶然丢掉东西。