0

I want to pass an integer array from controller to jquery, so that i would be able to collect these values, and on the basis of these values, i'll check checkboxes in partial view.

How can i do this ?

my controller code is as follws:

[HttpGet]
public PartialViewResult EditPartialView(string id)
{
    int selectedRoleId = Convert.ToInt32(id);
    Role selectedRole = objRP.GetRoleByID(selectedRoleId);            

    Array RoleAccessMap = entities.RoleAccessMaps.Where(x => (x.Role_ID == selectedRole.Role_ID && x.Project_ID == selectedRole.Project_ID)).ToArray();
    int count = RoleAccessMap.Length;

    for (int i = 0; i < count; i++)
    {
        int? RAM_Id = ((AgileMVC_EL.RoleAccessMap[])(RoleAccessMap))[i].RAM_ID;
        int? item_id = ((AgileMVC_EL.RoleAccessMap[])(RoleAccessMap))[i].Item_ID;
        int? actionValue = ((AgileMVC_EL.RoleAccessMap[])(RoleAccessMap))[i].Action_Value;

        // i want to put code for javascript/jquery function here.
    }
    return PartialView("Edit", selectedRole);
}

I want to pass these values (RAM_ID, item_ID, actioValue) to jquery function.

2 Answers 2

1

Best way is to use Viewbag as shown :

Just make a array from for loop(in controller action 'EditPartialView') and put that inside Viewbag.data.

In View retrieve Viewbag.data value in Jquery as :

var array = [];
var array = @Html.Raw(Json.Encode(@ViewBag.data));
for(var i =0; i<array.length;i++){......}
Sign up to request clarification or add additional context in comments.

2 Comments

@Mayank..i m saying that in controller action where you are looping through for loop there just make a simple one dimensional array and put it inside viewbag
i m not be able to understand as i m in dangerous state... he he he... so can u please display ur answer in a way u r trying to explain... i have also given my controller code to you.. Plz
0

You can use json object which is returned by your Controller

And call that controller by using jQuery.ajax() with dataType:'json' option

1 Comment

i want to pass array from controller to jquery, not to controller from jquery,,,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.