Click here to Skip to main content
15,898,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Multiple values</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
;



i want to pass this all languages from controller to java-script not like above(i.e; get all languages from database). How can i achieve this?
Posted
Updated 6-Jan-14 23:27pm
v3

XML
<script type="text/javascript">
 var movies =  @Html.Raw(Json.Encode(ViewBag.movies))
</script>
 
Share this answer
 
1) create a hidden control in your page
ASP.NET
<asp:HiddenField ID="hdnfld_availableTags" runat="server" />


in the code behind assign values to it as

C#
protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               hdnfld_availableTags.Value = "'ActionScript','AppleScript','Asp','BASIC','C','C++','Clojure','COBOL'";
           }
       }


and in javascript
XML
<script type="text/javascript">
        $(function () {
            var item = $('#hdnfld_availableTags').val();
            var ar = item.split(',');

            alert(ar);
        });
    </script>
 
Share this answer
 
Comments
Ajay_Babu 7-Jan-14 7:01am    
im using asp.net mvc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900