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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:16:25+00:00 2026-06-06T08:16:25+00:00

I can’t get my head around how to do this correctly: I’m working on

  • 0

I can’t get my head around how to do this correctly:

I’m working on a simple user membership application that is used to assign application roles to users. All I’m trying to do is popup an JQueryUI dialog that has a DropdownBox with all of the available applications and a dynamic checkbox list that will list the available roles for the selected application.

It needs to look like this (simple!):

enter image description here

I have managed to get the dialog box to display correctly thanks to Richard Covo’s tutorial here.

The code for the dropdownlist looks like this:

<label for='ApplicationsDropdownList'>Application:</label>

 @Html.DropDownListFor(
        x => x.SelectedApplicationId,
        new SelectList(Model.Applications, "Value", "Text"),
        "-- Select Application --",
             new
             {
                 id = "ApplicationsDropdownList",
                 data_url = Url.Action("ViewUserRolesForApplication", "UserRole")
             }
    ) 

</div>
<br />   <div id="RolesForApplication"></div>

And this is how I dynamically load the checkbox list of roles available for the selected application:

$('#ApplicationsDropdownList').change(function () {
            var url = $(this).data('url');
            var applicationId = $(this).val();
            $('#RolesForApplication').load(url, { applicationId: applicationId, selectedUserId: SelectedUserId })
        });
    });

The checkbox list is generated using the MVC checkboxlist extension:

@using (Html.BeginForm("SaveUsersRoles", "Index", FormMethod.Post))
{    


    @Html.CheckBoxList("Roles",                         // NAME of checkbox list (html 'name' property of each       
                   x => x.Roles,                        // data source (list of 'Cities' in our case)
                   x => x.RoleId,                       // field from data source to be used for checkbox VALUE
                   x => x.Code + " " + x.Description,   // field from data source to be used for checkbox TEXT
                   x => x.RolesForUser,
                   new HtmlListInfo(HtmlTag.table, 1))   
} 

The popup is displaying correctly and the roles are populating correctly but my confusion comes arises when saving. I’m assuming there should only be one viewmodel for this situation (I currently have 2), something like this:

public class ApplicationsForUserViewModel
{
    public Guid SelectedUserId  {get;set;}
    public int SelectedApplicationId { get; set; }
    public IEnumerable<SelectListItem> Applications { get; set; }

    public Application Application { get; set; }
    public IList<Role> Roles { get; set; } //all available roles
    public IList<Role> RolesForUser { get; set; } //roles that the user has selected

}

When pressing the save button on the dialog I enter the Edit method on the Index controller but the checkbox list is generated on a different form from a different controller, so how can I successfully model bind? Is there an easy way to do this?

Let me know if you would like to see more of the code so that you can point out further where I’m going wrong!

EDIT: The save button is currently hooked up to the edit action on the index controller.

Edit view:

@using (Ajax.BeginForm("Edit", "Index", new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace, 
            HttpMethod = "POST",
            OnSuccess = "updateSuccess"
        }, new { @id = "EditUserRolesForm" }))

and the jQuery UI dialog:

 $('#AddRolesDialog').dialog({                     
                buttons: {
                    "Save": function () {                      
                      $("#update-message").html('');
                      $("#EditUserRolesForm").submit();
                    }
                }
            });

So the dropdown is currently on the EditUserRoles form, while the checkbox list is on a seperate form – is this the right way to do it and should I rather be submitting the checkbox list form?

Thanks

  • 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-06T08:16:26+00:00Added an answer on June 6, 2026 at 8:16 am

    Your POST controller action could directly take the list of selected role ids:

    [HttpPost]
    public ActionResult SaveUsersRoles(int[] roles)
    {
        // the roles parameter will contain the list of ids of roles 
        // that were selected in the check boxes so that you could take 
        // the respective actions here
        ...
    }
    

    Now I suppose that you might also need the user id. So define a view model:

    public class SaveUsersRolesViewModel
    {
        public Guid SelectedUserId { get; set; }
        public int[] Roles { get; set; }
    }
    

    And then have your controller action take this view model:

    [HttpPost]
    public ActionResult SaveUsersRoles(SaveUsersRolesViewModel model)
    {
        ...
    }
    

    and of course don’t forget to include the user id as part of the form:

    @using (Html.BeginForm("SaveUsersRoles", "Index", FormMethod.Post))
    {    
        @Html.HiddenFor(x => x.SelectedUserId)
        @Html.CheckBoxList(
            "Roles",
            x => x.Roles,
            x => x.RoleId,
            x => x.Code + " " + x.Description,
            x => x.RolesForUser,                       
            new HtmlListInfo(HtmlTag.table, 1)
        )
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can anybody point me to a sample SPA application (source code) that is constructed
can I make my own headers in HTTP request ? e.g. This is normal
Can this be done? It seems like this should be possible. In general, I
Can someone explain it succinctly? Can it be used with non-Silverlight clients?
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can't figure out how to do this in a pretty way : I have

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.