0
我想用asp.net MVC4(razor語法)和databasefirst方法構建一個單頁的應用程序。 您可以看到我的應用程序的簡單模擬如下。Asp.net ModelView方法
-OPPORTUNITY<br />
--OPPORTUNITY DETAIL(1)<br />
---Seleted Solution-1<br />
---Seleted Solution-2<br />
---Seleted Solution-3<br />
--OPPORTUNITY DETAIL(2)<br />
---Seleted Solution-1<br />
---Seleted Solution-2<br />
--OPPORTUNITY DETAIL(3)<br />
---Seleted Solution-1<br />
---Seleted Solution-2<br />
---Seleted Solution-3<br />
我在表中有很多解決方案,並且有很多參數。什麼是在一頁中顯示所有信息的最佳途徑。我正嘗試使用創建一個新的viewmodel。但是我不確定它的性能,因爲它從表中獲取所有數據。
這裏是我的模型類..
OPPORNUTIES CLASS
namespace CRM_V1.Models
{
using System;
using System.Collections.Generic;
public partial class CRM_OPPORTUNITIES
{
public CRM_OPPORTUNITIES()
{
this.CRM_OP_ATTACHMENTS = new HashSet<CRM_OP_ATTACHMENTS>();
this.CRM_OPP_DETAILS = new HashSet<CRM_OPP_DETAILS>();
}
public decimal ID { get; set; }
public Nullable<decimal> COMPANYID { get; set; }
public Nullable<decimal> SEGMENTID { get; set; }
public Nullable<decimal> SEGMENTDETAILID { get; set; }
public Nullable<decimal> CUSTOMERID { get; set; }
public Nullable<decimal> PROJECTID { get; set; }
public Nullable<decimal> STATUSID { get; set; }
public Nullable<System.DateTime> CRDATE { get; set; }
public Nullable<decimal> CRUSER { get; set; }
public string CODE { get; set; }
public Nullable<System.DateTime> MDDATE { get; set; }
public Nullable<decimal> MDUSER { get; set; }
public Nullable<decimal> IS_VALID { get; set; }
public Nullable<decimal> OWNERID { get; set; }
public Nullable<decimal> PRJCTGRPID { get; set; }
public Nullable<decimal> ORDERSUMMARY { get; set; }
public string NOTES { get; set; }
public virtual CRM_COMPANIES CRM_COMPANIES { get; set; }
public virtual CRM_CUSTOMERS CRM_CUSTOMERS { get; set; }
public virtual ICollection<CRM_OP_ATTACHMENTS> CRM_OP_ATTACHMENTS { get; set; }
public virtual CRM_OP_STATUS CRM_OP_STATUS { get; set; }
public virtual ICollection<CRM_OPP_DETAILS> CRM_OPP_DETAILS { get; set; }
public virtual CRM_SEGMENTS CRM_SEGMENTS { get; set; }
public virtual CRM_SEGMENT_DETAILS CRM_SEGMENT_DETAILS { get; set; }
public virtual CRM_PROJECTS CRM_PROJECTS { get; set; }
public virtual CRM_PRJCT_GROUPS CRM_PRJCT_GROUPS { get; set; }
}
}
DETAIL CLASS
namespace CRM_V1.Models
{
using System;
using System.Collections.Generic;
public partial class CRM_OPP_DETAILS
{
public CRM_OPP_DETAILS()
{
this.CRM_OPP_DETAILS1 = new HashSet<CRM_OPP_DETAILS>();
this.CRM_REVENUE_PLAN = new HashSet<CRM_REVENUE_PLAN>();
this.CRM_SOLUTION_DISTRIBUTION = new HashSet<CRM_SOLUTION_DISTRIBUTION>();
}
public decimal ID { get; set; }
public string CODE { get; set; }
public Nullable<decimal> OPPID { get; set; }
public Nullable<decimal> ORDERAMOUNT { get; set; }
public Nullable<System.DateTime> ORDERDATE { get; set; }
public string ORDERCURRENCY { get; set; }
public Nullable<decimal> REVENUEAMOUNT { get; set; }
public Nullable<System.DateTime> REVENUEDATE { get; set; }
public Nullable<decimal> REVENUECURRENCY { get; set; }
public Nullable<short> MARGINRATE { get; set; }
public Nullable<System.DateTime> TARGETDATE { get; set; }
public Nullable<short> POSSIBILITY { get; set; }
public Nullable<decimal> STATUSID { get; set; }
public string NOTES { get; set; }
public Nullable<System.DateTime> CRDATE { get; set; }
public Nullable<decimal> CRUSER { get; set; }
public Nullable<System.DateTime> MDDATE { get; set; }
public Nullable<decimal> MDUSER { get; set; }
public Nullable<decimal> IS_VALID { get; set; }
public Nullable<decimal> TYPEID { get; set; }
public Nullable<decimal> OWNERID { get; set; }
public Nullable<decimal> AFFLDETAILID { get; set; }
public Nullable<decimal> REVENUEDOLLAR { get; set; }
public Nullable<decimal> ORDERDOLLAR { get; set; }
public Nullable<decimal> ISHAVEREVPLAN { get; set; }
public Nullable<decimal> SOLPLANDONE { get; set; }
public Nullable<decimal> SOLUTIONID { get; set; }
public string PAFDCANO { get; set; }
public Nullable<decimal> DCAKOD { get; set; }
public virtual CRM_OP_DETAIL_STATUS CRM_OP_DETAIL_STATUS { get; set; }
public virtual CRM_OPP_DETAIL_TYPE CRM_OPP_DETAIL_TYPE { get; set; }
public virtual CRM_OPPORTUNITIES CRM_OPPORTUNITIES { get; set; }
public virtual ICollection<CRM_OPP_DETAILS> CRM_OPP_DETAILS1 { get; set; }
public virtual CRM_OPP_DETAILS CRM_OPP_DETAILS2 { get; set; }
public virtual ICollection<CRM_REVENUE_PLAN> CRM_REVENUE_PLAN { get; set; }
public virtual ICollection<CRM_SOLUTION_DISTRIBUTION> CRM_SOLUTION_DISTRIBUTION { get; set; }
}
}
SOLUTION分佈狀態CLASS
namespace CRM_V1.Models
{
using System;
using System.Collections.Generic;
public partial class CRM_SOLUTION_DISTRIBUTION
{
public CRM_SOLUTION_DISTRIBUTION()
{
this.CRM_SOLUTION_VENDOR = new HashSet<CRM_SOLUTION_VENDOR>();
}
public decimal ID { get; set; }
public Nullable<decimal> OPPDETAILID { get; set; }
public Nullable<decimal> SOLUTIONID { get; set; }
public Nullable<decimal> CRUSER { get; set; }
public Nullable<System.DateTime> CRDATE { get; set; }
public Nullable<decimal> MDUSER { get; set; }
public Nullable<System.DateTime> MDDATE { get; set; }
public Nullable<decimal> AMOUNT { get; set; }
public Nullable<decimal> IS_VALID { get; set; }
public string CURRENCY { get; set; }
public Nullable<decimal> AMOUNTDOLLAR { get; set; }
public Nullable<decimal> MARGIN { get; set; }
public Nullable<decimal> MARGINRATE { get; set; }
public Nullable<decimal> DISTMARGIN { get; set; }
public Nullable<decimal> VENDORID { get; set; }
public Nullable<System.DateTime> VENDORDATE { get; set; }
public virtual CRM_OPP_DETAILS CRM_OPP_DETAILS { get; set; }
public virtual CRM_SOLUTIONS CRM_SOLUTIONS { get; set; }
public virtual CRM_VENDORS CRM_VENDORS { get; set; }
public virtual ICollection<CRM_SOLUTION_VENDOR> CRM_SOLUTION_VENDOR { get;
我開始創建一個MODELVIEW首先顯示一個機會和相關的細節,但我失敗了?
這裏是我的模型視圖類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CRM_V1.Models;
namespace CRM_V1.ViewModels
{
public class OppViewModel
{
public List<CRM_OPPORTUNITIES> OppList { get; set; }
public List<CRM_OPP_DETAILS> OppDetailList { get; set; }
}
}
我的控制器動作
public ActionResult addingDetailNew(decimal id = 0)
{
CRM_OPPORTUNITIES crm_opportunities = db.CRM_OPPORTUNITIES.Find(id);
var viewModel2 = new OppViewModel
{
viewModel2 = db.CRM_OPPORTUNITIES.ToList()
};
if (crm_opportunities == null)
{
return HttpNotFound();
}
return View(viewModel2);
}
最後我的看法。
@model CRM_V1.ViewModels.OppViewModel
@{
ViewBag.Title = "addingDetailNew";
}
<h2>addingDetailNew</h2>
@Html.DisplayFor(model => model.NOTES)
但我無法得到NOTES字段。 而我的第二個問題是如何獲得像model.CUSTOMERS.NAME這樣的加入字段。 ?
問候
我應該如何重新編寫模型視圖和控制器類來檢索所選的OPP和DETAIL信息。我試圖獲得選定的OPP,但我無法檢索DETAILS。 – umki
您可以返回一個唯一的OPP,然後在DETAILS上循環。 –
感謝您的幫助。但我有一個問題。我在我的viewmodel中只有一個CRM_OPP,並將其作爲OppList傳遞給視圖(實際上它不僅僅是一個對象的列表)。我如何獲得與foreach相關的CRM_OPP_DETAILS?代碼中的opportunity.CRM_OPP_DETAILS的輸出是什麼?是因爲EF獲得相關的詳細信息嗎? – umki