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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:07:02+00:00 2026-05-17T03:07:02+00:00

In MVC, is it possible to pass an array of string (List<string>) from C#

  • 0

In MVC, is it possible to pass an array of string (List<string>) from C# code to viewdata and then retrieve the value in the view? e.g:

C#:

List<string> names = new List<string>();
names.Add("a");
names.Add("b");
ViewData["names"] = names;

MVC view:

<script type="text/javascript">
var nameList = '<%= ViewData["names"] %>';
</script>

the code above runs OK but the returned javascript object in the view is “System.Collections.Generic.List`1[System.String]” which cannot be parsed to get the values out.

What is the right way to achieve that rather than build the string with delimiter in C# and split the value in the view?

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-05-17T03:07:03+00:00Added an answer on May 17, 2026 at 3:07 am

    You could use JavaScriptSerializer to generate the JS representation of your data.

    <script type="text/javascript">
    var nameList = <%= new JavaScriptSerializer().Serialize(ViewData["names"]) %>;
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to run the new ASP.NET MVC 2 Preview 2 on mono?
Possible Duplicate: Client Id for Property (ASP.Net MVC) In my View I'm using jquery
I'm trying to pass ViewData to my asp.net mvc masterpage for an mvc usercontrol
Is it possible to use Razor View Engine (ASP.NET MVC) together with .LESS (similar
In previous releases there were 3 ways to pass data from controller to view
Is it possible to assign javascript variable to c# variable in mvc razor view?
In ASP.NET MVC it's possible to choice between having a typed view were you
Possible Duplicate: ASP.NET MVC - View with multiple models Using ASP.NET MVC 3.0, how
Is it possible to post a form from one MVC site so that it
I'm considering the scenario where an MVC view would pass the model to a

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.