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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:33:53+00:00 2026-05-30T18:33:53+00:00

I downloaded the source files for jquery autocomplete to use in MVC3. Right now

  • 0

I downloaded the source files for jquery autocomplete to use in MVC3. Right now I have a DropDownListFor with a new SelectList(ViewBag.teachertype).

1st question: How can I change html code below to work with my ViewBag?:

      @*@Html.DropDownListFor(model => model.Teacher, new  SelectList(ViewBag.teachertype), new { style = "width:350px;" })*@

       <div class="ui-widget">
        <input id="tags" type="text"  />

        </div>    

Example function they gave me has just hard coded the names to put in the autocomplete. I need to bring my names in from my viewbag though.

   <script type="text/javascript">
     $(function () {
    var availableTags = [ "kelly", "joe", "tony", "Billy"];
    $("#tags").autocomplete({
        source: availableTags
    });
});
</script>
  • 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-30T18:33:54+00:00Added an answer on May 30, 2026 at 6:33 pm

    Your “ViewBag” data must be in the correct format for the auto complete plugin to work. Here is a quick example that will convert an array of “teacher types” to a javascript array:

    public ActionResult Index()
    {
        var types = new string[] {"Kindergarten", "HighSchool", "preschool" };
        var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        ViewBag.teachertype = serializer.Serialize(types);
        return View();
    }
    

    Within the related view the following will create a textbox that is wired up to the jquery autocomplete plugin along with the teacher types set within the controller:

    @Html.TextBox("teachertype")
    
    <script type="text/javascript">
    
        $(function() {
            var types = @Html.Raw(ViewBag.teachertype);
            $("#teachertype").autocomplete({
                source: types 
            });
        });
    
    </script>
    

    On a side note, utilizing the ViewData dictionary (ViewBag is simply a dynamic type) will eventually cause you headaches. IMO you would be better off to create a view model and include your “teacher types”.

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

Sidebar

Related Questions

I have downloaded DeepEmailMiner-v1-source.zip from http://sourceforge.net/projects/deepemailminer/files/DeepEmailMiner/Version%20v1/ . But when I try to execute DeepMailMiner.java
I'm looking for documentation on boost::threadpool. I downloaded the source and documentation zip files.
I downloaded the jquery files and tried to include them in my Site.Master, and
I downloaded some source files on a Mac that were previously part of some
I downloaded a zip of source files containing a C# project with multiple entry
I have downloaded source code for some software from svn on Linux and want
I have downloaded the Android source code by following the steps given here http://source.android.com/source/downloading.html
I have used the a jquery script that is used to upload files: http://aquantum-demo.appspot.com/file-upload
I've downloaded source files for mingw . Could someone please tell me what steps
Sometimes when i try to build/compile a downloaded source, i get following warning: ld:

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.