У меня есть следующий код в моем контроллере:
public ActionResult Index(int Id)
{
Landbase _db = new Landbase();
OwnerWorkingInterests workingInterests = new OwnerWorkingInterests();
//Owner owner = new Owner();
var query = (from wg in _db.WorkingInterestGroups
join wi in _db.WorkingInterests on wg.Id equals wi.WorkingInterestGroupId
join l in _db.Leases on wg.LeaseId equals l.Id
where wi.OwnerId.Equals(Id)
select new OwnerWorkingInterests()
{
LeaseId = l.Id,
WorkingInterestAmount = wi.WorkingInterestAmount,
WorkingInterestGroupName = wg.Name,
ClientAlias = l.ClientAlias,
Lessor = l.Lessor,
Lessee = l.Lessee,
VolDocNumber = l.VolumeDocumentNumber,
County = l.County,
District = l.District
}).ToList();
//List<string> OwnerWorkingInterest = query.ToList<string>();
return View(query);
}
У меня есть следующий код, на мой взгляд:
<div id="OwnerWorkingInterests" class="tab-pane fade">
<h3>Working Interests</h3>
<table class="table">
<thead>
<tr>
<td>Lease Id:</td>
<td>Working Int:</td>
<td>WI Group Name:</td>
<td>Alias:</td>
<td>Lessor:</td>
<td>Lessee:</td>
<td>VolPg:</td>
<td>County:</td>
<td>District0:</td>
</tr>
</thead>
<tbody>
@foreach (var owi in OwnerWorkingInterests)
{
<tr>
<td>@owi.LeaseId</td>
<td>@owi.WorkingInterestAmount</td>
<td>@owi.WorkingInterestGroupName</td>
<td>@owi.ClientAlias</td>
<td>@owi.Lessor</td>
<td>@owi.Lessee</td>
<td>@owi.VolDocNumber</td>
<td>@owi.County</td>
<td>@owi.District</td>
</tr>
}
</tbody>
</table>
</div>
Я думал, что это заполнит таблицу правильной информацией
Это модель просмотра:
namespace LandPortal.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class WorkingInterest
{
public int Id { get; set; }
public int? OwnerId { get; set; }
[Column("WorkingInterest")]
public decimal? WorkingInterestAmount { get; set; }
[StringLength(45)]
public string CreateUser { get; set; }
[StringLength(45)]
public string ModifyUser { get; set; }
public Guid? CreateUserId { get; set; }
public Guid? ModifyUserId { get; set; }
public DateTime? CreateDate { get; set; }
public DateTime? ModifyDate { get; set; }
public int? WorkingInterestGroupId { get; set; }
public WorkingInterestGroup WorkingInterestGroup { get; set; }
public decimal? ORRI { get; set; }
public int? ORRIOwnerId { get; set; }
public virtual Owner Owner { get; set; }
}
}
Итак, что происходит, когда я запускаю его в отладчике, выдает очень расплывчатую ошибку. Буквально просто написано Ошибка: при обработке вашего запроса произошла ошибка. Итак, я предполагаю, что список заполняется, но не работает в foreach в представлении. Я могу ошибаться в этот момент.
Вот директивы модели для представления
@using LandPortal.Models
@using LandPortal.ViewModels
@using Microsoft.Ajax.Utilities
@model LandPortal.Models.Owner