지난 1 월 반 동안이 답변을 찾으려고 노력했지만 때로는 너무 가깝지만 지금까지는 행운이없는 것 같습니다. LINQ 쿼리를 정의한 컨트롤러가 있는데 목록 뷰에 결과를 전달하는 방법을 파악하려고합니다. 다음은 컨트롤러 코드 :컨트롤러에서 뷰로 데이터 전달
:namespace CMS.Controllers
{
public class SurveyController : Controller
{
private SupportEntities supdb = new SupportEntities();
private BuisnessEntities bsdb = new BuisnessEntities();
//
// GET: /Survey/BizSurveyC
public ViewResult BizSurveyC(string nipaKey, string bOrg)
{
// use the next two lines for testing and then either delete or comment them out.
nipaKey = "22";
bOrg = "MPC";
var Cquery = from Mstr in bsdb.BizOrgInsts
join Dat in bsdb.BizSurveyQ on Mstr.ID equals Dat.MASTERID
where Mstr.NIPAKEY == nipaKey & Mstr.FULCIRCORG == bOrg
orderby Mstr.STREETSUFX, Dat.ADDRESS, Mstr.NUMBER
select new { MasterId = Mstr.ID, Name = Mstr.OLDNAME, Mstr.ADDRESS, Mstr.NIPAKEY, Dat.SURVEYDATE, SurveyId = Dat.ID, Dat.RESURVEYOF, Dat.STAMP };
//ViewBag.BizQuery = Cquery;
ViewData["BizQuery"] = new SelectList(Cquery);
return View();
}
}
}
당신은 내가을 ViewData와 Viewbag하지만 지금까지 행운으로 여기
이 일이 지금 표시하는 방법을 시도 보면 알 수 있듯이
의 ViewModel 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CMS.Models
{
public class BizSurveyCVM
{
public long? MasterId { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string NipaKey { get; set; }
public string Date { get; set; }
public long? SurveyId { get; set; }
public long? Resurvey { get; set; }
public string DateStamp { get; set; }
}
}
수정 작업
var Cquery = (from Mstr in bsdb.BizOrgInsts
join Dat in bsdb.BizSurveyQ on Mstr.ID equals Dat.MASTERID
where Mstr.NIPAKEY == nipaKey & Mstr.FULCIRCORG == bOrg
orderby Mstr.STREETSUFX, Dat.ADDRESS, Mstr.NUMBER
select new BizSurveyCVM
{
MasterId = Mstr.ID,
Name = Mstr.OLDNAME,
Address = Mstr.ADDRESS,
NipaKey = Mstr.NIPAKEY,
Date = Dat.SURVEYDATE,
SurveyId = Dat.ID,
Resurvey = Dat.RESURVEYOF,
DateStamp = Dat.STAMP
}).ToList();
return View(Cquery);
}
BizSurveyC보기
@model List<CMS.Models.BizSurveyCVM>
<table>
<tr>
<th>
MasterId
</th>
<th>
Name
</th>
<th>
Address
</th>
<th>
NipaKey
</th>
<th>
Date
</th>
<th>
SurveyId
</th>
<th>
Resurvey
</th>
<th>
DateStamp
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.MasterId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.NipaKey)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.SurveyId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Resurvey)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateStamp)
</td>
</table>
여기
결과이다 :
미안 아직 이미지를 저장 허용하지만보기에 내가 가지고 있지 HEADERS하지만 데이터가 .
분명히보기 또는 쿼리에서 할 일이 있지만 모든 사람의 도움 덕분에 상황이 훨씬 나아졌습니다. 대단히 감사합니다
MVC 버전은 무엇입니까? – RedFilter
보기 코드를 알려주십시오. – swapneel
당신이 지금까지 가지고있는 것은 괜찮습니다. 그래서 뷰에서 viewdata를 호출하는 방법이 문제라고 생각됩니다. – Brian