请理解我是asp.net的新手。我使用QueriesTableAdapeter创建了一个数据结构,现在我想更新我的视图和控制器,以便我可以显示数据。
我的控制器是:
+ (NSArray *) getData:(NSString *)entity pred:(NSString *)pred predArray:(NSArray *)predArray context:(NSManagedObjectContext *)context {
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entity];
[request setPredicate:[NSPredicate predicateWithFormat:pred argumentArray:predArray]];
NSError *error = nil;
NSArray *results = [context executeFetchRequest:request error:&error];
if (!results) {
NSLog(@"Error fetching Employee objects: %@\n%@", [error localizedDescription], [error userInfo]);
abort();
}
return results;
}
}
我的观点到目前为止:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace KCware.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
public ActionResult AxiomDS()
{
//return AxiomDS();
return View();
}
}
这是我项目的结构:
答案 0 :(得分:1)
尝试关注Getting Started with Entity Framework 6 Code First using MVC 5上的示例项目对您来说将是一个良好的开端,包括您正在寻找的方法,如下所示:
Student \ Index.cshtml视图在表格中显示此列表:
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstMidName)
</th>
<th>
@Html.DisplayNameFor(model => model.EnrollmentDate)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstMidName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EnrollmentDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
<强>更新强>
如果您正在寻找一种从数据集中检索数据的方法,您可以查看this页面。
希望这会有所帮助......