Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:01:59+00:00 2026-05-26T14:01:59+00:00

I have a mvc 3 vb.net app that I need to generate several viewbags

  • 0

I have a mvc 3 vb.net app that I need to generate several viewbags for… I tried the following code to just drop a variable at the end of the viewbag name after each loop but it wont take it.. It says “Object variable or With block variable not set.” when it his the viewbag.status(p) line on the second pass it makes through the loop…

     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

And the view looks like this:

  @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

Any ideas???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:01:59+00:00Added an answer on May 26, 2026 at 2:01 pm

    I simply created the viewbag inside the for each loop of my view… So that way everytime it went through the loop to handle each item in the table it would generated that items viewbag for the dropdown as well..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC web app and have a function that I need
So, I have an asp.net mvc app that is being worked on by multiple
I have an ASP.NET MVC App, which use EF code First, for some reason
I have a an ASP.NET MVC application that will need to access file resources
I have a basic ASP.NET MVC 3 app. I have a basic action that
I have an ASP.NET MVC app that I have been building, and I am
I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
I have a medium sized asp.net MVC app. It consumes a service layer that
I have an ASP.NET MVC app that stores all SQL DateTime in UTC, so
In my ASP.Net MVC app, I have the following controllers HomeController ExController ExController has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.