私はMVC(Webformsから来たもの)が非常に新しいので、Webformsで単純な方法を見つけるのに苦労しています。各行のMVC実行コード/機能結果LINQクエリ
私はLINQクエリを使用してデータベースからのデータ(プロパティ)のリストを持っており、このデータはビューに表示されており、このデータの各行には一意のIDがあります。
私が達成しようとしていることは2つあります。それぞれのプロパティでfuntionを実行して値を返し、ビューに表示する必要があります。 また、そのプロパティ(一意のID)にリンクされているデータを(1行以上)取得する必要がありますし、これらのビューを反復処理する必要があるため、プロパティの下にデータを表示するためにforeachステートメントをネストしますビューでは、しかし、私はちょうどこのクエリを実行する方法とビューで表示する方法がありません。
webformsでは、ItemDataBoundイベント(リピーターを使用している場合)でItemDataBoundで関数を呼び出したり、より多くのデータを要求したり、ネストされたリピーターに表示したりすることができます。
コントローラー - 各プロパティ
public class ViewingViewModel
{
[Key]
public int ID { get; set; }
public int CaseID { get; set; }
public DateTime Date { get; set; }
public string Applicant { get; set; }
public int AgentID { get; set; }
}
のために視聴するためのプロパティ
public ActionResult Index()
{
// list of pre-offer cases
IList<CurrentViewModel> CaseList = new List<CurrentViewModel>();
var query = from cr in context.CaseRegs
join c in context.PgsClients on cr.ClientID equals c.ClientID
join s in context.PgsSites on cr.SiteID equals s.SiteID into scr from s in scr.DefaultIfEmpty()
join b in context.Buyins on cr.CaseID equals b.CaseID into bcr from b in bcr.DefaultIfEmpty()
where cr.arcStatus == "Current" && cr.withdrawn == null
orderby cr.CaseID
select new CurrentViewModel
{
CaseID = cr.CaseID,
RegistrationDate = cr.RegistrationDate.GetValueOrDefault(),
ClientName = c.ClientName,
ClientCode = c.ClientCode,
SiteName = cr.SiteName,
SiteName2 = s.SiteName,
ClientPlot = cr.ClientPlot,
ContactName = cr.ContactName,
PxpStatus = cr.arcStatus,
CaseStatus = cr.caseStatus,
OwnerTitle = cr.ownerTitle,
OwnerFirstname = cr.ownerFirstname,
OwnerSurname = cr.ownerSurname,
PropertyAddress = cr.propertyAddress,
PropertyAddress2 = cr.propertyAddress2,
PropertyAddress3 = cr.propertyAddress3,
PropertyTown = cr.propertyTown,
PropertyCounty = cr.propertyCounty,
PropertyPostcode = cr.propertyPostcode,
TargetCompletionDate = b.TargetCompletionDate
};
CaseList = query.ToList();
return View(CaseList);
}
モデル
public class CurrentViewModel
{
[Key]
public int CaseID { get; set; }
public DateTime RegistrationDate { get; set; }
public int ClientID { get; set; }
public string ClientName { get; set; }
public string ClientCode { get; set; }
public int SiteID { get; set; }
public string SiteName { get; set; }
public string SiteName2 { get; set; }
public string ClientPlot { get; set; }
public string ContactName { get; set; }
public string PxpStatus { get; set; }
public string CaseStatus { get; set; }
public string OwnerTitle { get; set; }
public string OwnerFirstname { get; set; }
public string OwnerSurname { get; set; }
public string PropertyAddress { get; set; }
public string PropertyAddress2 { get; set; }
public string PropertyAddress3 { get; set; }
public string PropertyTown { get; set; }
public string PropertyCounty { get; set; }
public string PropertyPostcode { get; set; }
[DataType(DataType.Date)]
public DateTime? TargetCompletionDate { get; set; }
}
ビュー
@model IEnumerable<PGS.Models.ViewModels.CurrentViewModel>
@using PGS.Utilities
@{
Layout = "~/Views/Shared/_Main_Template.cshtml";
}
<h1>@ViewBag.Title</h1>
<table class="table">
<thead>
<tr>
<th colspan="7">
<span class="record-count">@ViewBag.RecordCount</span>
</th>
</tr>
<tr>
<th>Case</th>
<th>Start Date</th>
<th>Target Completion</th>
<th>Site/Plot</th>
<th>Name</th>
<th>Property</th>
<th>Client</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
string RowClassName = "row-" + @item.CaseID;
<tr class="row-click @RowClassName" data-url="/Case/Details/@item.CaseID/">
<td>
@Html.DisplayFor(modelItem => item.CaseID)
</td>
<td>
@item.RegistrationDate.Date.ToString("dd-MMM-yyyy")
</td>
<td>
@if (item.TargetCompletionDate.HasValue)
{ @item.TargetCompletionDate.Value.ToString("dd-MMM-yyyy") }
</td>
<td>
@Extensions.SitePlotFormat(item.ClientPlot, item.SiteName, item.SiteName2)
</td>
<td>
@Extensions.VendorNameFormat(item.OwnerTitle, item.OwnerFirstname, item.OwnerSurname)
</td>
<td>
@Extensions.PropertyShortAddressFormat(item.PropertyAddress, item.PropertyTown, item.PropertyCounty, item.PropertyPostcode)
</td>
<td>
@Html.DisplayFor(modelItem => item.ClientCode)
</td>
</tr>
}
</tbody>
</table>
モデルのリストを取得します。
試したサンプルデータと関連コードをご記入ください – Shyju
現在、ありがとうございます。 – JBoom
コード全体を投稿する必要はありません。関連するコードだけを投稿してください(あなたが求めている質問に対して)。どのプロパティをどのような方法で実行したいと思いますか?あなたがその方法を実行するのを止めているのは何ですか? – Shyju