저는 여러 개의 뷰백을 생성해야하는 mvc 3 vb.net 앱이 있습니다. 다음 코드를 사용하여 뷰백 이름의 끝에 변수를 놓으려고했습니다. 각 루프하지만 그것을 가져 가지 않을거야 .. 그것은 "개체 변수 또는 With 블록 변수가 설정되지 않았습니다." 그것은 자신이 루프를 만든다 번째 패스에 viewbag.status (p) 라인 ...각 루프에 대해 뷰백 이름에 변수를 붙입니다.
Dim p As Integer = 0
For Each registrant In b
Dim _regi As attendance = registrant
Dim _status As New List(Of String)
If Not String.IsNullOrWhiteSpace(_regi.Completed_Class) Then
_status.Add(_regi.Completed_Class)
End If
_status.Add("--")
_status.Add("Absent")
_status.Add("Left Early")
_status.Add("Completed")
ViewBag._status(p) = _status
p = p + 1
Next
하고 뷰는 다음과 같다 때
@ModelTYPE List(Of xxxxxx.attendance)
@Code
ViewData("Title") = "Class Attendance Record"
End Code
@Using Html.BeginForm
@<fieldset>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Registrant ID</th>
<th>Course Status</th>
<th>Comments</th>
</tr>
@For r As Integer = 0 To Model.Count - 1
Dim i As Integer = r
@Html.HiddenFor(Function(m) m(i).id)
@Html.HiddenFor(Function(m) m(i).course_ref)
@<tr>
<td>@Html.DisplayFor(Function(m) m(i).firstName)
@Html.HiddenFor(Function(m) m(i).firstName)
</td>
<td>@Html.DisplayFor(Function(m) m(i).lastName)
@Html.HiddenFor(Function(m) m(i).lastName)
</td>
<td>@Html.DisplayFor(Function(m) m(i).reg_id)
@Html.HiddenFor(Function(m) m(i).reg_id)
</td>
<td>@Html.DropDownListFor(Function(m) m(i).Completed_Class, New SelectList(ViewBag._status(i)))
@Html.HiddenFor(Function(m) m(i).Completed_Class)
</td>
<td>@Html.TextBoxFor(Function(m) m(i).Comments, New With {.class = "AttenComment"})
@Html.HiddenFor(Function(m) m(i).Comments)
</td>
</tr>
Next
</table>
<p><input type="submit" name="submit" /></p>
</fieldset>
End Using
어떤 아이디어 ???
위의 편집을 참조하십시오. 뷰가 포함되어있어 고유성이 필요한 이유를 알 수 있습니다. – Skindeep2366
해당 부분 작동 ... 문제는 어떻게 뷰백에서 꺼내야합니까? dropdownlistfor 인덱스 번호 – Skindeep2366
에서 인덱스 번호 실제로 그것을 알아 냈어 ... 나는 그것에 열심히 생각하고 있었다. 내 견해는 이미 작업의 일부였다. – Skindeep2366