조사를 위해 VS2012, MVC 4, Entity Framework 4.0 프로젝트가 있습니다. 결과를 내 컨트롤러로 다시 가져 오는 방법을 찾는 데 어려움이 있습니다. 대부분의 답은 드롭 다운 목록에서 나옵니다. 각 질문마다 하나씩 있습니다. 내보기에 필요한 모든 정보가있는 간결한 개체의 테이블을 평평하게보기 위해 뷰를 사용하고 있습니다. SQL보기는 다음과 같습니다.ViewModel에없는 컨트롤러로 결과 반환
SELECT TOP (100) PERCENT
Questionaires.QuestionaireKey,
Questionaires.QuestionaireName,
Sections.SectionKey,
Sections.SectionName,
QuestionaireSections.DefaultSequence AS QAS_Sequence,
Questions.QuestionKey,
Questions.Question,
SectionQuestions.DefaultSequence AS SQ_Sequence,
QuestionTypes.QuestionTypeKey,
QuestionTypes.QuestionTypeName,
AnswerListCodes.AnswerListCodeKey,
AnswerListCodes.AnswerListCodeName,
QuestionAnswerListCodes.DefaultSequence AS QALC_Sequence
FROM dbo.Questionaires AS Questionaires
INNER JOIN dbo.QuestionaireSections AS QuestionaireSections
ON Questionaires.QuestionaireKey = QuestionaireSections.QuestionaireKey
INNER JOIN dbo.Sections AS Sections
ON QuestionaireSections.SectionKey = Sections.SectionKey
INNER JOIN dbo.SectionQuestions AS SectionQuestions
ON Sections.SectionKey = SectionQuestions.SectionKey
INNER JOIN dbo.Questions AS Questions
ON SectionQuestions.QuestionKey = Questions.QuestionKey
INNER JOIN dbo.QuestionTypes AS QuestionTypes
ON Questions.QuestionTypeKey = QuestionTypes.QuestionTypeKey
INNER JOIN dbo.QuestionAnswerListCodes AS QuestionAnswerListCodes
ON Questions.QuestionKey = QuestionAnswerListCodes.QuestionKey
INNER JOIN dbo.AnswerListCodes AS AnswerListCodes
ON QuestionAnswerListCodes.AnswerListCodeKey = AnswerListCodes.AnswerListCodeKey
각 질문에는 AnswerListCodes에서 가능한 답이 있습니다. vw_Questions 엔티티는 읽기 전용입니다. 저장해야하는 데이터는 Answers & EvaluationAnswers Answers 테이블에 있습니다. 내 컨트롤러 코드는 지금까지 있습니다 :
이에 대한 display that I'm looking 결과public ActionResult Index()
{
ViewBag.Answers = db.Answers.ToList();
ViewBag.EvaluationAnswers = db.EvaluationAnswers.ToList();
return View(db.vw_Questions.ToList());
}
가 여기에 있습니다.
각 드롭 다운 목록에서 선택한 답변을 내 컨트롤러로 다시 가져 오는 방법이 표시되지 않습니다. 일부 답변도 텍스트가됩니다.
보기 코드 :
@model IEnumerable<Prototype_06.Models.vw_Questions>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<style>
table { border-collapse:collapse; }
table,th, td {border: 1px solid gray; }
</style>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<table>
@foreach (var group in (Model.OrderBy(x => x.QAS_Sequence).GroupBy(item => item.SectionName)))
{
<tr>
<th colspan="3">@group.Key</th>
</tr>
foreach (var item in group.OrderBy(x => x.SQ_Sequence).GroupBy(subItem => subItem.Question).Distinct()) {
<tr>
<td> </td>
<td>@item.Key</td>
<td>
<select>
<option value="@Guid.Empty"></option>
@foreach (var ans in item.OrderBy(x => x.QALC_Sequence))
{
<option value="@ans.AnswerListCodeKey">@ans.AnswerListCodeName</option>
}
</select>
</td>
</tr>
}
}
</table>
<p>
<input type="submit" value="Save" />
</p>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
그래서 당신이 원하는 MVC 기본 사항에 대한 자세한 내용을 추천, 컨트롤러는 그것을 알고 새로운 뷰 모델을 반환합니다. 나는? – Blaise
여전히 혼란 스럽습니다. 양식이 제출되면 양식의'action' 속성에 지정된 작업을 컨트롤러에 게시합니다. 그럼,보기에 코드를 보여 주시겠습니까? – Blaise
핵심 부분은 MVC 방식으로 드롭 다운 목록을 렌더링하는 방법을 찾는 것이라고 생각합니다. 내가 선택한 데이터를 게시 된 데이터에 표시 할 수 있다고 생각하고 있습니다. –