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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:33+00:00 2026-06-13T13:54:33+00:00

This is my first post so please go easy on me fellas. I am

  • 0

This is my first post so please go easy on me fellas. I am trying to implement a create form that utilizes jquery autocomplete. The create form allows users to enter data that will be saved to my database, via a submit button. Here is my code:

Controller

    // GET: /Inspection1/Create
    public ActionResult Create()
    {
        InspectionInfo model = new InspectionInfo
        {
            Submitted = DateTime.Now,
            Contact = new Contact()
        };

        ViewBag.CountyName = new SelectList(db.Counties, "CountyName", "CountyName");


        return View(model);
    }

    //
    // POST: /Inspection1/Create

    [HttpPost]
    public ActionResult Create(InspectionInfo inspectioninfo)
    {
            if (ModelState.IsValid)
        {
            db.InspectionInfos.Add(inspectioninfo);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(inspectioninfo);
    }

    // this allows for autocompletion behavior
    public ActionResult QuickSearchContact(string term)
    {
        var contacts = db.Contacts
                        .Where(r => r.ContactName.Contains(term))
                        .Take(10)
                        .Select(r => new { label = r.ContactName });
        return Json(contacts, JsonRequestBehavior.AllowGet);

    }

Models

  public class InspectionInfo
  {
    [Key]
    public int InspectionId { get; set; }

    [DataType(DataType.Date)]
    public virtual DateTime Submitted { get; set; }
    [DataType(DataType.MultilineText)]
    [MaxLength(1000)]
    public string Comments { get; set; }

    [Required]
    public Contact Contact { get; set; }


 public class Contact
 {
    [Key]
    public string ContactName { get; set; }

View:

<div class="editor-label">
        @Html.LabelFor(model => model.Contact)
    </div>
    <div class="editor-field">
        <input type ="text" name ="q" data-autocomplete=  
       "@Url.Action("QuickSearchContact", "Inspection")"/> 
        @Html.ValidationMessageFor(model => model.Contact.ContactName)
    </div>

JS

$(document).ready(function () {

  $(":input[data-autocomplete]").each(function () {

  $(this).autocomplete({ source: $(this).attr("data-autocomplete")});
  });

The autocomplete function seems to be working fine. It will pull column data from the database as I require. However, any data entered in the autocomplete text box, appears NULL in the database after the user has saved the form. Help here would be greatly appreciated.

  • 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-06-13T13:54:34+00:00Added an answer on June 13, 2026 at 1:54 pm

    For model binding to work, generally input names must match property names of your model. Surprisingly, you have named your input “q”

    <input type ="text" name ="q" data-autocomplete="..."/> 
    

    Just rename it according to your model

    <input type ="text" name="Contact.ContactName" data-autocomplete="..."/> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here so go easy. I am trying to build
This is my first post, so please go easy on me if I say
Long time watcher and this is my first post so please go easy on
please be easy - first post! Looking to modify the following script: http://jonraasch.com/blog/a-simple-jquery-slideshow Love
This is my first post so please bear with me. I'm trying to execute
this is my first post. please be kind :) i'm trying to get picture
This is my first post on stackoverflow, so please excuse me if my question
This is my first post on Stack, so please bear with me if I
This is my first post in this forum, so please, be patient with me.
This is my first post and I my first experience with jquery. I have

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.