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 6359107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:28:30+00:00 2026-05-24T23:28:30+00:00

I have a page here that shows two classgroups – groups/lists of students –

  • 0

I have a page here that shows two classgroups – groups/lists of students – of which you can select some => click the button => selected students change classgroups.

By default the first classgroup is selected in another page, and the second list of students are students who don’t have a classgroup yet.

Now I want to add a dropdownlist with all the classgroups in the database, and then the user (teacher) can select one and the second list of classes changes to the selected classgroup.

The problem is that I can’t seem to get the selected classgroup in my controller (I’m fairly new to mvc3, I’m in my second year of applied informatics atm and we don’t get books/a course on this but I can’t seem to get it to work)

Controlleraction (DocentController):

public ViewResult ToonStudenten(string id) //id = klasnaam
        {
            var GeselecteerdeKlas = StudentRepo.getStudentenByKlas(id);
            var TweedeKlas = StudentRepo.getStudentenZonderKlas();
            var AlleKlassen = KlasRepo.FindAllKlasNaam();
            var KlasNaam = id;
            ViewBag.EersteKlas = id;
            ViewBag.TweedeKlas = "Deze studenten kregen nog geen klas toegewezen, gelieve de studenten die u naar klas" + id + " wil verzetten te selecteren";

            return View(new ToonStudentenModel(GeselecteerdeKlas, TweedeKlas, AlleKlassen, KlasNaam));
        }

        [HttpPost, ActionName("ToonStudenten")]
        public ActionResult VeranderStudentenKlas(string[] deleteInputsKlas1, string[] deleteInputsKlas2, string id, string id2)//, string klasnaam1, string opdrachtID)
        {

            //TODO: Lijsten worden goed mee gegeven, klasnaam nog NIET (= null)
            if (deleteInputsKlas2 == null && deleteInputsKlas1 == null)
            {

                ModelState.AddModelError("", "Er werden geen Studenten geselecteerd");
                return RedirectToAction("ToonStudenten", "Docent", new { id = id });
            }

            foreach (var item in deleteInputsKlas1)
            {
                try
                {
                    StudentRepo.VeranderKlas(item, null);
                }
                catch (Exception er)
                {
                    ModelState.AddModelError("", "Failed on ID " + item + " : " + er.Message);
                    return View("error");
                }
            }

            foreach (var item in deleteInputsKlas2)
            {
                try
                {
                    StudentRepo.VeranderKlas(item, id);
                }
                catch (Exception er)
                {
                    ModelState.AddModelError("", "Failed on ID " + item + " : " + er.Message);
                    return View("error");
                }
            }

            StudentRepo.SaveChanges();
            return RedirectToAction("ToonStudenten", "Docent", new { id = id });

        }


    }
}

ViewModel

{
    public class ToonStudentenModel
    {
        public IEnumerable<Student> EersteKlas { get; set; }
        public IEnumerable<Student> TweedeKlas { get; set; }
        public IEnumerable<Student> GeselecteerdUitEersteKlas { get; set; }
        public IEnumerable<Student> GeselecteerdUitTweedeKlas { get; set; }
        public IEnumerable<string> KlassenDropDown { get; set; }
        public string KlasNaam { get; set; }
        public string geselecteerdeKlasUitDropDown { get; set; }


        public ToonStudentenModel(IEnumerable<Student> GeselecteerdeKlas,
            IEnumerable<Student> AndereKlasOfStudZonderKlas, IEnumerable<string> KlassenDropDown, string KlasNaam)
        {         
            EersteKlas = GeselecteerdeKlas;
            TweedeKlas = AndereKlasOfStudZonderKlas;
            this.KlassenDropDown = KlassenDropDown;
            this.KlasNaam=KlasNaam;
        }
    }
}

View:

@using (Html.BeginForm(new { id = Model.KlasNaam } ))
{

<div>

@Html.ValidationSummary()

</div>

<div style="float:right;">

    <input type="submit" value="Delete Selected Values" />

</div>

<h2>Index</h2>
<div>Studenten @ViewBag.EersteKlas</div>
<table>

<tr>
    <th></th>
    <th></th>
    <th>
        Studentennummer
    </th>
    <th>
        Voornaam
    </th>
    <th>
        Naam
    </th>
</tr>

@foreach (var item in Model.EersteKlas)

{

<tr>
    <td>
        <input type="checkbox" name="deleteInputsKlas1" value="@item.StudentID" />
    </td>
    <td>
        @Html.ActionLink("Details", "Details", new { id = item.StudentID }) |
    </td>
    <td>
        @item.StudentID
    </td>
    <td>
        @item.Voornaam
    </td>
    <td>
        @item.Naam
    </td>
</tr>
}
</table>

@ViewBag.TweedeKlas
<table>

<tr>
    <th></th>
    <th></th>
    <th>
        Studentennummer
    </th>
    <th>
        Voornaam
    </th>
    <th>
        Naam
    </th>
</tr>

@foreach (var item in Model.TweedeKlas)
{

    <tr>
        <td>
            <input type="checkbox" name="deleteInputsKlas2" value="@item.StudentID" />
        </td>
        <td>
            @Html.ActionLink("Details", "Details", new { id = item.StudentID }) |
        </td>
        <td>
            @item.StudentID
        </td>
        <td>
            @item.Voornaam
        </td>
        <td>
            @item.Naam
        </td>
    </tr>

}
</table>
<input type="hidden" name="id" value = @Model.KlasNaam />
    <input type="hidden" name="id1" value = @Model.opdrachtID />
  <div>OF: Kies een andere klas om studenten in klas @Model.KlasNaam te steken:
  @Html.DropDownListFor(model => Model.KlassenDropDown, new SelectList(Model.KlassenDropDown))




  </div>
}
<div>
    @Html.ActionLink("Terug naar uw klassen", "ToonKlassen", new{id = Model.opdrachtID });
</div>
  • 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-24T23:28:31+00:00Added an answer on May 24, 2026 at 11:28 pm

    ended up not using Ajax but just passing the object through the form to the post method and use some if’s there

    View

    @Html.DropDownListFor(model => Model.geselecteerdeKlasUitDropDown, new SelectList(Model.KlassenDropDown), "--Zonder klas--")
    

    Controller:

    [HttpPost, ActionName("ToonStudenten")]
            public ActionResult VeranderStudentenKlas(string[] deleteInputsKlas1, string[] deleteInputsKlas2, string id, int id1, string geselecteerdeKlasUitDropDown, string searchpara1, string searchpara2)// id = klasnaam1, id1 = opdrachtID, id2 = klasgroep2)
            {
    
                if (deleteInputsKlas2 == null && deleteInputsKlas1 == null)
                {
    
                        ModelState.AddModelError("", "Er werden geen Studenten geselecteerd");
                        return RedirectToAction("ToonStudenten", "Docent", new { id = id, id1 = id1, geselecteerdeKlasUitDropDown = geselecteerdeKlasUitDropDown, searchpara1 = searchpara1, searchpara2 = searchpara2 });
                }
    
                    if (deleteInputsKlas1 != null)
                        foreach (var item in deleteInputsKlas1)
                        {
                            try
                            {
                                if (geselecteerdeKlasUitDropDown == "")
                                    StudentRepo.VeranderKlas(item, null);
                                else
                                    StudentRepo.VeranderKlas(item, geselecteerdeKlasUitDropDown);
                            }
                            catch (Exception er)
                            {
                                ModelState.AddModelError("", "Fout bij Student met ID " + item + " : " + er.Message);
                                return View("error");
                            }
                        }
    
                    if (deleteInputsKlas2 != null)
                        foreach (var item in deleteInputsKlas2)
                        {
                            try
                            {
                                StudentRepo.VeranderKlas(item, id);
                            }
                            catch (Exception er)
                            {
                                ModelState.AddModelError("", "Failed on ID " + item + " : " + er.Message);
                                return View("error");
                            }
                        }
    
                    StudentRepo.SaveChanges();
                    return RedirectToAction("ToonStudenten", "Docent", new { id = id, id1 = id1, geselecteerdeKlasUitDropDown = geselecteerdeKlasUitDropDown, searchpara1 = searchpara1, searchpara2 = searchpara2 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that has two drop down lists on it and a
Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
I have a page that is generated which inserts an HTML comment near the
Here on this page, Scott Hanselman shows two examples from Micro-ORMs Dapper and Massive,
Here's my scenario: I have a page containing several links; each link is meant
OK, Here is my problem, I have a master page with a HEAD section
Here's what I have: Quarter Sheet Flyer (4 per page) as a PSD or
Here's the scenario: I have a textbox and a button on a web page.
here's what I'm trying to do : On a page, I would have a
I have a page using <ul> lists for navigation (Javascript changes the styling to

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.