我有以下2個表:填充字段值作爲數據列查看MVC
我想在這種格式在我看來:
伊夫放入其中,我通過我的模型傳遞給視圖一個IEnumerable:
public class BudgetEntryNotesVM
{
public string AccountNumber { get; set; }
public string AccountDescription { get; set; }
public IEnumerable<BudgetNoteLineEntryVM> BudgetNoteLineEntryList { get; set; }
}
public class BudgetNoteLineEntryVM
{
public int pkiNotesLineEntriesId { get; set; }
public int fkiAccountId { get; set; }
public string NotesColumnName { get; set; }
public string Value { get; set; }
public bool isNewLineItem { get; set; }
public int Sequence { get; set; }
}
我使用下面的填充數據:
public IEnumerable<BudgetNoteLineEntryVM> GetBudgetNoteLineEntry(int accId)
{
IEnumerable<BudgetNoteLineEntryVM> AccountsLineEntriesIList = new List<BudgetNoteLineEntryVM>();
//var query2 =(from)
var query = (from NC in _context.Notes_Columns
join NLE in _context.Notes_Line_Entries on NC.pkiNotesColumnsId equals NLE.fkiNotesColumnId
where NLE.fkiAccountId == accId
select new BudgetNoteLineEntryVM
{
pkiNotesLineEntriesId = NLE.pkiNotesLineEntriesId,
fkiAccountId = NLE.fkiAccountId,
NotesColumnName = NC.NotesColumnName,
Value = NLE.Value,
isNewLineItem = NLE.isNewEntry,
Sequence = NC.Sequence
}).Distinct().OrderBy(n => n.Sequence);
AccountsLineEntriesIList = query;
return AccountsLineEntriesIList;
}
和IM填充它和傳球它是這樣的:
public ActionResult BudgetNoteLineEntry(int accId)
{
BudgetEntryNotesVM NVM = new BudgetEntryNotesVM();
NVM.AccountNumber = _budgetEntryRepository.GetAccountName(accId);
NVM.AccountDescription = _budgetEntryRepository.GetAccountDescription(accId);
NVM.BudgetNoteLineEntryList = _budgetEntryRepository.GetBudgetNoteLineEntry(accId);
return PartialView("_ShowAccountBudgetLineEntries", NVM);
}
我根本無法想到了解決辦法,我希望有人可能會導致我在正確的方向。
謝謝。
對不起,我應該寧願向我展示2張表格,以及我正在從中提取的數據。兩者之間的聯繫是fkiNotesColumnId - Id相信這是標識哪些值屬於哪個列的字段?希望這有助於多一點? – AxleWack
@AxleWack你可以創建一個二維數組,其中所有數據將被排序,並將其與第一個表中的標題分開呈現。 'ViewModel'應該包含已經格式化的數據。 –
我會研究它,並試試看。謝謝安德烈 – AxleWack