我已經創建了我的連接字符串,它似乎連接沒有錯誤。我只是試圖輸出各種各樣的ID
,但它的表現就像沒有任何東西!沒有錯誤,但從ToList沒有結果()
該表充滿了記錄......它也不輸出任何錯誤。我怎樣才能調試這樣的東西?
型號:
namespace MvcApplication1.Models
{
public class Directory
{
public int ID { get; set; }
public bool DELETED { get; set; }
public Guid CREATED_BY { get; set; }
public DateTime DATE_ENTERED { get; set; }
public Guid MODIFIED_USER_ID { get; set; }
public DateTime DATE_MODIFIED { get; set; }
public Guid USER_ID { get; set; }
public Guid BRANCH_ID { get; set; }
}
public class MyDbContext : DbContext
{
public DbSet<Directory> Directories { get; set; }
}
}
查看:
@model IEnumerable<MvcApplication1.Models.Directory>
@foreach (var item in Model) {
<tr>
<td>
@item.ID
</td>
</tr>
}
控制器:
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
private Models.MyDbContext db = new Models.MyDbContext();
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View(db.Directories.ToList());
}
}
}
您確定它指向正確的數據庫,而不是一個空目錄表嗎? –
你的'@ Html.DisplayFor(modelItem => item.ID)'沒有意義。你確定你將正確的模型傳遞給模板嗎? – CAbbott
@JeffSiver我不確定如何確定,但我認爲如果出現某種錯誤,它會投訴。 – user1477388