troubleshooting Question

C# MVC Auto completed issue

Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland asked on
.NET MVC.NET ProgrammingC#* ASP.NET Core
19 Comments1 Solution13 ViewsLast Modified:
Hi Experts,

I have issue with my code. But when i'm debugging and i can see records are coming but it's not properly display in the web page


See debug results

Jquery example from  : https://jqueryui.com/autocomplete/#default
@section Scripts {
    <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"
            ];
            $("#tags").autocomplete({
                source: 'api/JobSearch/search'
            }

            );
        });



    </script>

    @{await Html.RenderPartialAsync("_ValidationScriptsPartial"); }

Open in new window

but if I replace with this  Source :
 $("#tags").autocomplete({
                source:availableTags

Open in new window

it will work for availableTag Array. 
Html
  <div class="form-group">

        <div class="col-md-12">
            @Html.EditorFor(model => model.JobNumber, new { htmlAttributes = new { @class = "form-control" } })



        </div>
    </div>

Open in new window

APIcontroller
 [Route("api/[controller]")]
    [ApiController]
    public class JobSearchController : ControllerBase
    {
        
        public JobSearchController()
        {
                
        }
        [Produces("application/json")]
        [HttpGet("Search")]
        public async Task<IActionResult> Search()
        {

            try
            {

                string term = HttpContext.Request.Query["term"].ToString();
                SqlConnection con = new SqlConnection(connectionname);
                //select the Job number
                //===================================================================================================
                con.Open();

                SqlCommand jobSqlCommand = con.CreateCommand();
                jobSqlCommand.CommandText = "FindJobNumbersp";
                jobSqlCommand.CommandType = CommandType.StoredProcedure;
                jobSqlCommand.Parameters.Add("@Search", SqlDbType.NVarChar).Value = term;
                List<jobDetails> Joblist = new List<jobDetails>();
                SqlDataAdapter da = new SqlDataAdapter(jobSqlCommand);
                DataSet ds = new DataSet();
                da.Fill(ds);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {

                    Joblist.Add(new jobDetails
                    {
                        JobNumber = dr["job"].ToString()

                    }
                    ); ;

                }
                jobSqlCommand.Dispose();
                con.Close();
                return Ok(Joblist);

            }
            catch (Exception)
            {

                return BadRequest();
            }


        }

Open in new window

_Layout.cshtml
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - TestJquery</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
    <link href="~/lib/jquery-ui-1.12.1.custom/jquery-ui.min.css" rel="stylesheet" />
    <link href="~/lib/datetimepicker-master/datetimepicker-master/build/jquery.datetimepicker.min.css" rel="stylesheet" />

    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">

</head>

Open in new window

_ValidationScriptsPartial.cshtml


<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>


Open in new window


if anyone can show why is data is not displaying ,i will really appreciated.


ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 19 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 19 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004