troubleshooting Question

A tab show the same data as the other one in MVC project

Avatar of jwebster77
jwebster77 asked on
JavaScriptHTMLC#* Razor* ASP .NET MVC 5
1 Comment1 Solution30 ViewsLast Modified:
Hello,

I do not understand why I have two tabs that are displaying the same data.  The columns headers appear as they should, so it is the rest of the page, but the data is the same on both tabs.  
One thing I noticed is that as of now the data displaying is that of the fifth tab(called Knowledge) and if I flip their order on the index page then the data showing in both tabs is the other one(fourth tab; called Tasks).
The page and the code is about the same on both tabs.
I have been working on this for hours but I do not seem to find a solution. Code below, it is a lot but I included everything so you know exactly what I did.
Thank you so much.

INDEX PAGE
<ul class="nav nav-tabs">
    <li><a data-toggle="tab" href="#fourthTab">IT Tasks</a></li>
    <li><a data-toggle="tab" href="#fifthTab">Knowledge</a></li>
</ul>

<div class="tab-content">
    <div id="fourthTab" class="tab-pane fade in">@Html.Action("ViewAllTasks")</div>
    <div id="fifthTab" class="tab-pane fade in">@Html.Action("ViewAllKnowledgeRealOne")</div>    
</div>

CONTROLLER
//-------------------------IT TASKS--------------------------------------------------------------------
        public ActionResult ViewAllTasks()
        {
            HelpDeskDBHandle dbhandle = new HelpDeskDBHandle();
            return View(dbhandle.GetITTasksList());
        }


        //LIST IT TASKS
        public JsonResult ListITTasks()
        {
            HelpDeskDBHandle hdDB = new HelpDeskDBHandle();
            return Json(hdDB.GetITTasksList(), JsonRequestBehavior.AllowGet);
        }


//*******GET TASKS DETAILS*******************
         public List<ITTasksModel> GetITTasksList()
        {
            connection();
            List<ITTasksModel> Ittaskslist = new List<ITTasksModel>();

            string constring =                               ConfigurationManager.ConnectionStrings["HelpDeskSupportConn"].ToString();
            string query = "SELECT * FROM ITTasks";
            using (SqlConnection con = new SqlConnection(constring))
            {
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    cmd.Connection = con;
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            Ittaskslist.Add(new ITTasksModel
                            {
                                ITNumber = Convert.ToInt32(sdr["ITNumber"]),
                                ITDescription = Convert.ToString(sdr["ITDescription"]),
                                ITEnterDate = Convert.ToString(sdr["ITEnterDate"]),
                                ITAssignedTo = Convert.ToString(sdr["ITAssignedTo"]),
                                ITEstimatedCompletion = Convert.ToString(sdr["ITEstimatedCompletion"]),
                                ITPriority = Convert.ToString(sdr["ITPriority"]),
                                ITFrom = Convert.ToString(sdr["ITFrom"]),
                                ITStatus = Convert.ToString(sdr["ITStatus"])
                            });
                        }
                    }
                    con.Close();
                }
                return Ittaskslist;
            }
        }


 //-------------------------KNOWLEDGE------------------------------------------------------------------
        //VIEW ALL KNOWLEDGE
        public ActionResult ViewAllKnowledgeRealOne()
        {
            HelpDeskDBHandle dbhandle = new HelpDeskDBHandle();
            return View(dbhandle.GetKnowledgeList());
        }


        //LIST KNOWLEDGE
        public JsonResult ListKnowledgeRealOne()
        {
            HelpDeskDBHandle hdDB = new HelpDeskDBHandle();
            return Json(hdDB.GetKnowledgeList(), JsonRequestBehavior.AllowGet);
        }


// **********GET KNOWLEDGE DETAILS********
        public List<KnowledgeRealOneModel> GetKnowledgeList()
        {
            connection();
            List<KnowledgeRealOneModel> KnowledgeRealOneList = new List<KnowledgeRealOneModel>();

            string constring =                                 ConfigurationManager.ConnectionStrings["HelpDeskSupportConn"].ToString();
            string query = "SELECT * FROM KnowledgeRealOne";
            using (SqlConnection con = new SqlConnection(constring))
            {
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    cmd.Connection = con;
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            KnowledgeRealOneList.Add(new KnowledgeRealOneModel
                            {
                                Number = Convert.ToInt32(sdr["Number"]),
                                Subject = Convert.ToString(sdr["Subject"]),
                                //ITEnterDate = Convert.ToDateTime(sdr["ITEnterDate"]),
                                From = Convert.ToString(sdr["From"]),
                                DateCreated = Convert.ToString(sdr["DateCreated"]),
                                AssignedDate = Convert.ToString(sdr["AssignedDate"]),
                                RequestType = Convert.ToString(sdr["RequestType"]),
                                Body = Convert.ToString(sdr["Body"]),
                                DateSubmitted = Convert.ToString(sdr["DateSubmitted"]),
                                Category = Convert.ToString(sdr["Category"])
                            });
                        }
                    }
                    con.Close();
                }
                return KnowledgeRealOneList;
            }
        }

KNOWLEDGE VIEW
@*--------------KNOWLEDGE VIEW----------------------------------------------------------*@

@model IEnumerable<HelpDeskSupport.Models.KnowledgeRealOneModel>

@{
    Layout = null;
}

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Knowledge</title>

    <script src="~/Scripts/KnowledgeRealOneJS.js"></script>
</head>

<div class="container">
    <h2>Knowledge</h2>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModalKnowledge"          onclick="clearTextBox();">Add New Knowledge</button><br /><br />

    <table class="display table table-striped table-bordered" id="knowledgeRealOneTable">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Number)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Subject)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.From)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.DateCreated)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.AssignedDate)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.RequestType)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Body)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.DateSubmitted)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Category)
                </th>
            </tr>
        </thead>

        <tbody class="tbody">
            @foreach (var item in Model)
            {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Number)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Subject)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.From)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DateCreated)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.AssignedDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.RequestType)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Body)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DateSubmitted)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Category)
                </td>
            </tr>
            }
        </tbody>
    </table>
</div>

TASKS VIEW
@*TASKS VIEW--------------------------------------------------------------------------------------*@


@model IEnumerable<HelpDeskSupport.Models.ITTasksModel>

@{
    Layout = null;
}

<head>
    <meta name="viewport" content="width=device-width" />
    <title>ViewAllTasks</title>

    <script src="~/Scripts/ITTasksJS.js"></script>
</head>

<div class="container">
    <h2>IT Tasks</h2>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"       onclick="clearTextBox();">Add New Task</button><br /><br />

    <table class="display table table-striped table-bordered" id="knowledgeTable">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.ITNumber)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITDescription)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITEnterDate)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITAssignedTo)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITEstimatedCompletion)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITPriority)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITFrom)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ITStatus)
                </th>
            </tr>
        </thead>

        <tbody class="tbody">
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITNumber)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITDescription)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITEnterDate)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITAssignedTo)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITEstimatedCompletion)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITPriority)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITFrom)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ITStatus)
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>

KNOWLEDGE JAVASCRIPT
jQuery(function () {
    loadDataKnowledge();
});

//Load Data function
function loadDataKnowledge() {
    $.ajax({
        url: "/Tickets/ListKnowledgeRealOne",
        type: "GET",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (result) {
            var html = '';
            $.each(result, function (key, item) {
                html += '<tr>';
                html += '<td>' + item.Number + '</td>';
                html += '<td>' + item.Subject + '</td>';
                html += '<td>' + item.From + '</td>';
                html += '<td>' + item.DateCreated + '</td>';
                html += '<td>' + item.AssignedDate + '</td>';
                html += '<td>' + item.RequestType + '</td>';
                html += '<td>' + item.Body + '</td>';
                html += '<td>' + item.DateSubmitted + '</td>';
                html += '<td>' + item.Category + '</td>';
                html += '<td><a href="#" onclick="return getbyNumber(' + item.Number + ')">Edit</a> |                   <a href="#" onclick="DeleteKnowledge(' + item.Number + ')">Delete</a></td>';
                html += '</tr>';
            });
            $('.tbody').html(html);
            alert("Successful load KNOWLEDGE");
        },
        error: function (errormessage) {
            alert(errormessage.responseText);
        }
    });
}

TASKS JAVASCRIPT
$(document).ready(function () {
    loadData();
});

//Load Data function
function loadData() {
    $.ajax({
        url: "/Tickets/ListITTasks",
        type: "GET",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (result) {
            var html = '';
            $.each(result, function (key, item) {
                html += '<tr>';
                html += '<td>' + item.ITNumber + '</td>';
                html += '<td>' + item.ITDescription + '</td>';
                html += '<td>' + item.ITEnterDate + '</td>';
                html += '<td>' + item.ITAssignedTo + '</td>';
                html += '<td>' + item.ITEstimatedCompletion + '</td>';
                html += '<td>' + item.ITPriority + '</td>';
                html += '<td>' + item.ITFrom + '</td>';
                html += '<td>' + item.ITStatus + '</td>';
                html += '<td><a href="#" onclick="return getbyTicketNumber(' + item.ITNumber +             ')">Edit</a> | <a href="#" onclick="DeleteItTask(' + item.ITNumber + ')">Delete</a></td>';
                html += '</tr>';
            });
            $('.tbody').html(html);
            alert("Successful Load TASK");
        },
        error: function (errormessage) {
            alert(errormessage.responseText);
        }
    });
}

Thanks a lot again!


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros