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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:43:50+00:00 2026-05-25T01:43:50+00:00

I have an Action which returns a partial view, and I would like to

  • 0

I have an Action which returns a partial view, and I would like to store a list of id’s in the ViewBag.property = ids (somewhere temporary) and add them to an actionLink into the object HtmlAttributes

How can this be done, or is there a better way to do this?

public PartialViewResult MyAction() {
    // do something and return a partialview
    List/Array/Dictionary ids;  // ?
    foreach (MyClass c in List<MyClass>) { 
        // Doing something else but need to store the ID somewhere for the ActionLink
        ids[] =c.Id ?
        ids.Add(c.Id) = c.Id; ?
    }
    ViewBag.myProperty = ? //(e.g. some List or Array to Json?)
}

In the partialview

@Html.ActionLink("action", ..., new { idArray = @ViewBag.myProperty } )

Is this possible, or is there a better alternative? Can this be done passing a Json object to the htmlAttributes in an actionLink?

System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new    
    System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(ids);
ViewBag.myProperty = sJSON;
  • 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-25T01:43:51+00:00Added an answer on May 25, 2026 at 1:43 am

    I would use the session (HttpContext.Current.Session) to store a variable like this instead of viewbag. This way, you would not attach the array to the link, just the session key.

    In the code:

    string mylistkey = ?;//choose a meaningful and unique key name
    HttpContext.Current.Session.add(mylistkey, list); //your list in your example
    ViewBag.myProperty = mylistkey; // just put the key in the viewbag

    In the pagecode:
    @Html.ActionLink("action", ..., new { idSessionKey = @ViewBag.myProperty } )

    In your target page, you use the key to retrieve the actual array from the session:
    string sessionKey = HttpContext.Current.Request.QueryString[idSessionKey];
    List<MyClass> mylist=(List<MyClass>)(
    HttpContext.Current.Session[sessionKey]);
    HttpContext.Current.Session.Remove(sessionKey);

    There are many other ways to do this, and I think you can make your JSON idea work as well. This would be my suggestion because it keeps your URL line more readable.

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

Sidebar

Related Questions

I have a view page with ajax.action link which returns a partial view from
I have a controller action which I would like to call another controller action.
I have a controller action which renders a partial view: public ActionResult Details(int id)
i have view which looks something like this : <% using (Ajax.BeginForm(new AjaxOptions {
I have an action which I need to post forward onto another action if
I have a regular form with a url as action to which the form
I'm struggling here with a problem: I have a controller questions which has action
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
I have an action called List that shows the results of a search. It
I have a view which is composed of top, left and bottom headers and

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.