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

  • Home
  • SEARCH
  • 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 7704599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:43:01+00:00 2026-05-31T23:43:01+00:00

I need to get string array or list with ajax and Action, this is

  • 0

I need to get string array or list with ajax and Action, this is my Implementation:

This is my html Dom of view of Index action in AccessMenuController:

<div class="RoleAccess">
   <select name="RoleDropDown">
    <option value="0">Select Role</option>
    <option value="61AD3FD9-C080-4BB1-8012-2A25309B0AAF">AdminRole</option>
    <option value="8A330699-57E1-4FDB-8C8E-99FFDE299AC5">Role2</option>
    <option value="004E39C2-4FFC-4353-A06E-30AC887619EF">Role3</option>
   </select>
</div>

My Controller:

namespace MyProject.Areas.GlobalAccess.Controllers {

public class AccessMenuController : Controller {

    public ActionResult Index() { return View();}

    [HttpPost]
    public JsonResult RoleDropDownChanged(string roleId) {

     Guid RoleId = new Guid(roleId);

    //Some implement

    List<string> actions = new List<string>();
    for(int i = 0; i <= 10; i++) 
            actions.Add(i.ToString());

return Json(actions.ToArray(), JsonRequestBehavior.AllowGet);

   }
  }
}

and the script:

$(document).ready(function () {

//Handle Checks of Actions by RoleName Changed
$('div.RoleAccess select').change(function () {
    RoleChangeHandler();
});

function RoleChangeHandler() {

    $.ajax({
        url: '@Url.Action("RoleDropDownChanged")',
        type: 'POST',
        data: { 'roleId': '61AD3FD9-C080-4BB1-8012-2A25309B0AAF' },
        dataType: 'json',
        processData: false,
        contentType: 'application/json; charset=utf-8',
        success: function (data) { SuccessRoleChangeHandler(data); },
        error: OnFailRoleChangeHandler
    });
    return false;
}


function SuccessRoleChangeHandler(data) {

    alert("in success role change");

}

function OnFailRoleChangeHandler(result) {
    alert('in OnFailRoleChangeHandler');

}

And the problem is with all change of dropdown just Onfail function run and alert me “in OnFailRoleChangeHandler”, also I check the RoleDropDownChanged Action with breakpoint and that never run, where is the problem?

UPDATE

when I load the page by chrome there is an error in console window:
http://MyProject/GlobalAccess/AccessMenu/@Url.Action(%22RoleDropDownChanged%22) 404 (Not Found) jquery-1.7.1.js:8102

  • 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-31T23:43:03+00:00Added an answer on May 31, 2026 at 11:43 pm

    Remove this setting:

    contentType: 'application/json; charset=utf-8',
    

    You are not sending any JSON to the server.

    If you want to keep this setting then make sure that you are sending a valid JSON to your server:

    data: JSON.stringify({ 'roleId': '61AD3FD9-C080-4BB1-8012-2A25309B0AAF' })
    

    So:

    $.ajax({
        url: '@Url.Action("RoleDropDownChanged")',
        type: 'POST',
        data: { 'roleId': '61AD3FD9-C080-4BB1-8012-2A25309B0AAF' },
        success: SuccessRoleChangeHandler,
        error: OnFailRoleChangeHandler
    });
    

    should work (at least it does for me) with the following action:

    [HttpPost]
    public ActionResult RoleDropDownChanged(Guid roleId) 
    {
        var actions = Enumerable.Range(1, 10).Select(x => x.ToString()).ToList();
        return Json(actions);
    }
    

    UPDATE:

    According to your comments it looks like you are trying to use server side helpers in a separate javascript which is not possible. Here’s what I would suggest you. Start by providing the url when generating your dropdown:

    <div class="RoleAccess">
        @Html.DropDownListFor(
            x => x.RoleDropDown, 
            Model.Roles, 
            "-- Select role --",
            new { 
                data_url = Url.Action("RoleDropDownChanged") 
            }
       )
    </div>
    

    and then in your separate javascript file:

    $(document).ready(function() {
        $('div.RoleAccess select').change(function () {
            var url = $(this).data('url');
            $.ajax({
                url: url,
                type: 'POST',
                data: { 'roleId': '61AD3FD9-C080-4BB1-8012-2A25309B0AAF' },
                success: function(result) {
                    alert('success');
                },
                error: function() {
                    alert('error');
                }
            });        
        });    
    });
    

    and then of course you could replace the hardcoded roleId with the currently selected value:

    data: { 'roleId': $(this).val() }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

((List<string>)Session[answera]).Add(xle.InnerText); I need to perform this operation, but I get Object reference not set
I have this string: 123-456-7 I need to get this string: 1234567 How I
What is the Java equivalent of JavaScript's String.match() I need to get an array
I have an array list ArrayList<String> firstname; In this I am storing n number
>>> a = str(datetime.now()) >>> a '2012-03-22 11:16:11.343000' I need to get a string
I'm using Fluent NHibernate and need to get my Connection String from the connection.connection_string
I need to get it as a string to use elsewhere in the program,
I need to get all substrings from string. For ex: StringParser.GetSubstrings([start]aaaaaa[end] wwwww [start]cccccc[end], [start],
I need to get the last character of a string. Say I have testers
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug

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.