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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:19:57+00:00 2026-06-01T17:19:57+00:00

for last two days i was trying to figure out how to update a

  • 0

for last two days i was trying to figure out how to update a checkboxlist dynamicly when a new item in dropdownlist is selected by help of javascript.

Ive done same thing for a week ago where i should do update to a from a dropdownlist to a dropdownlist.

What ive got so far :

View

@using (Html.BeginForm())
{
    @Html.DropDownListFor(x => x.User, (IEnumerable<SelectListItem>)Model.UserList, "-- vælg bruger --")
    if (Model.checkboxlist != null)
    {
       for (var i = 0; i < Model.checkboxlist.Count; i++)
       {
        <div class="editor-label">
           @Html.CheckBoxFor(c => Model.checkboxlist[i].check)
            @Html.LabelFor(c => Model.checkboxlist[i].Id, Model.checkboxlist[i].Id)
            @Html.HiddenFor(c => Model.checkboxlist[i].Id)

        </div>
       }
    }
}
<script type="text/javascript">
    $('#User').change(function () {
    alert('HEJ!');
        var selectedUser = $(this).val();
        alert(selectedUser);
        if (selectedUser != null && selectedUser != '-- vælg bruger --' && selectedUser != '') {
            $.getJSON('@Url.Action("getPdfCheckBoxList","Admin")', { username: selectedUser },
            function (employee) {

                var checkboxlist = $('#checkboxlist');
                checkboxlist.empty();

                $.each(employee, function (index, employee) {
                    checkboxlist.append($('<checkbox/>', {
                        checked = 'false'
                    }));
                });
            });

        }
    });
</script>

when i am loading view Model.checkboxlist is null cause i dont return anything to model apart of dropdownlist items.

ControllerAction :

public ActionResult getPdfCheckBoxList(String username)
{
    MethodService service = new MethodService();
    var list = new List<PDFCheckBoxList>();


    foreach (var pdfCheckBoxList in getPDFFileNames(username))
    {
        list.Add(new PDFCheckBoxList { check = false, Id = pdfCheckBoxList });
    }
    return Json(list, JsonRequestBehavior.AllowGet);
} 

Right now even Alert(“HEJ”) doesnt even get fired, and i simply cant figure out why… Help please?

  • 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-06-01T17:19:58+00:00Added an answer on June 1, 2026 at 5:19 pm

    You could use partial views and have your controller action return a partial and build the markup on the server instead of doing it on the client:

    @using (Html.BeginForm())
    {
        @Html.DropDownListFor(
            x => x.User, 
            Model.UserList, 
            "-- vælg bruger --",
            data_url = Url.Action("getPdfCheckBoxList", "Admin")
        )
        <div id="checkboxlist">
            @if (Model.checkboxlist != null)
            {
                @Html.Partial("_checkboxlist", Model.checkboxlist)
            }
        </div>
    }
    

    and then define _checkboxlist.cshtml:

    @model IEnumerable<PDFCheckBoxList>
    @{
        ViewData.TemplateInfo.HtmlFieldPrefix = "checkboxlist";
    }
    @Html.EditorForModel()
    

    and finally the editor template ~/Views/Shared/EditorTemplates/PDFCheckBoxList.cshtml which will be rendered for each element:

    @model PDFCheckBoxList
    <div class="editor-label">
        @Html.CheckBoxFor(c => c.check)
        @Html.LabelFor(c => c.Id, Model.Id)
        @Html.HiddenFor(c => c.Id)
    </div>
    

    Now you could modify your javascript like so:

    <script type="text/javascript">
        // Now that we no longer have any server side 
        // code here we could externalize this script
        // into a separate javascript file
    
        $('#User').change(function () {
            if (selectedUser != null && selectedUser != '') {
                var selectedUser = $(this).val();
                var url = $(this).data('url');
                var data = { username: selectedUser };
                $('#checkboxlist').load(url, data);
            }
        });
    </script>
    

    and finally your getPdfCheckBoxList action:

    public ActionResult getPdfCheckBoxList(String username)
    {
        var service = new MethodService();
        var list = getPDFFileNames(username)
            .Select(x => new PDFCheckBoxList 
            { 
                check = false, 
                Id = x 
            })
            .ToList();
        return PartialView("_checkboxlist", list);
    }
    

    If you want to build the markup on the client and have the controller action return JSON I would recommend you using some javascript templating framework.

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

Sidebar

Related Questions

I'm trying to figure out how to get only the last two files within
I've spent the last 2 days trying to figure this out, basically I have
after pulling my hair out for two days trying to figure this issue out
I've been banging my head for the last two days trying to figure this
I am new to programming (day 3) and I spent the last two days
I've been all over the place for the last two days trying to find
hi am noob at blender and opengles.for the last two days i was trying
I've spent the last two days trying to get some bloody data to export
For last two days I am trying to profile a java application on a
I've spent the last two days hunting JavaScript memory leaks in my web project

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.