我需要在單個視圖中顯示多個表。這似乎是一個問題,因爲該視圖只允許從我可以告訴的一個模型定義。我嘗試過實施一種解決方法,但一直沒有成功。 具體而言,我收到錯誤消息:「傳入字典的模型項類型爲'System.Data.Entity.DbSet 1[BillingApp.Models.HEADER_RECORD]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [BillingApp.Models.tbl1join]'。」在同一視圖中調用多個SQL語句表
觀
@model IEnumerable<BillingApp.Models.tbl1join>
@{
ViewBag.Title = "TABLE 01 DISPLAY";
Layout = "../Shared/Layout2.cshtml";
}
@section featured2 {
<html>
<body>
~excluding tables because there are too many fields~
</body></html>
}
類接合兩個表(tbl1join.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BillingApp.Models
{
public class tbl1join
{
public HEADER_RECORD HeaderRecord { get; set; }
public HEADER_EXTENSION_RECORD ExtensionRecord { get; set; }
}
}
模型說明:
HEADER_RECORD.cs
namespace BillingApp.Models
{
using System;
using System.Collections.Generic;
public partial class HEADER_RECORD
{
public int HRID { get; set; }
public string TABLE_NUMBER { get; set; }
public string COMPANY { get; set; }
public string STATE_CODE { get; set; }
public string BILL_CODE { get; set; }
public string RECORD_TYPE { get; set; }
public string MASK_EXTENSION_ID { get; set; }
public string OVERPAYMENT_LIMIT { get; set; }
public string UNDERPAYMENT_LIMIT { get; set; }
public string REFUND_ACTION_OVR { get; set; }
public string REFUND_ACTION_PAR { get; set; }
public string REFUND_ACTION_RTN_PRM { get; set; }
public string REFUND_ACTION_CNC { get; set; }
public string EFT_PAC_OPTION { get; set; }
public string EFT_PAC_NOTICE { get; set; }
public string EFT_PAC_NSF_LIMIT { get; set; }
public string PREMIUM_ROUNDING { get; set; }
public string DB_CC_OPTION { get; set; }
public string NSF_CHECK_LIMIT { get; set; }
public string NSF_CHECK_OPTION { get; set; }
public string FIRST_TERM_BILLING { get; set; }
public string CARRY_DATE_OPTION { get; set; }
public string ENDORSEMENT_DAYS { get; set; }
public string DATE_METHOD { get; set; }
public string RENEWAL_OPTION { get; set; }
public string DROP_DAYS { get; set; }
public string MULTI_PAY_IND { get; set; }
public string MINIMUM_INSTALLMENT { get; set; }
public string ENDORSEMENT_ACTION { get; set; }
public string I_OR_S_OPTION_DAYS { get; set; }
public string S_OPTION_PERCENT { get; set; }
public string SERVICE_CHARGE_PREPAID { get; set; }
public string REINSTATE_OPTION { get; set; }
public string CASH_WITH_APPLICATION { get; set; }
public string DB_CC_NOTICE { get; set; }
public string DOWN_PAY_DAYS { get; set; }
public string MONTH_BY_TERM { get; set; }
public string LEAD_MONTHS { get; set; }
public string INITIAL_MONTHS { get; set; }
public string DB_CC_REJECTS { get; set; }
public string RETURN_ENDORSEMENT_OPTION { get; set; }
public string RETURN_SPLIT_OPTION_PERCENT { get; set; }
public string AUTOMATED_REFUND_DAYS { get; set; }
public string RENEWAL_OPTION_BILL_PLAN { get; set; }
public string EFFECTIVE_DATE { get; set; }
public string MISC_DATA { get; set; }
public string MISC_DATA2 { get; set; }
}
}
HEADER_EXTENSIO N_RECORD.cs
namespace BillingApp.Models
{
using System;
using System.Collections.Generic;
public partial class HEADER_EXTENSION_RECORD
{
public int ERID { get; set; }
public string ETABLE_NUMBER { get; set; }
public string ECOMPANY { get; set; }
public string ESTATE_CODE { get; set; }
public string EBILL_CODE { get; set; }
public string ERECORD_TYPE { get; set; }
public string EMASK_EXTENSION_ID { get; set; }
public string OVERPAYMENT_TOLERANCE_PERCENT { get; set; }
public string UNDERPAYMENT_TOLERANCE_PERCENT { get; set; }
}
}
的控制器(BillingController.cs)
public ActionResult HeaderExtensionRecord()
{
{
return View(db.HEADER_EXTENSION_RECORD);
}
}
public ActionResult HeaderRecordTable1()
{
{
return View(db.HEADER_RECORD);
}
}
更新:
新增tbl1join作爲控制器的返回類型,但給一個錯誤,說這是一個類型被用作變量。
public ActionResult HeaderRecordTable1()
{
{
return View(IEnumerable<tbl1join>);
}
}
你有你的觀點接受'IEnumerable'。它看起來像你已經設置好了,爲什麼你沒有控制器操作返回'IEnumerable '? –
Jonesopolis
2014-10-01 19:49:45
這兩個模型之間有關係嗎?你不能使用導航屬性/關係來加入數據嗎? – mheptinstall 2014-10-01 20:00:05
你需要以某種方式填充你的模型,即創建'tbl1join's基於你的數據庫,但是你需要加入他們 – Jonesopolis 2014-10-01 20:01:42