Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

can anyone help me again? below are my codes. the data of my table will not display.
please help it runs properly with no error.

C#
namespace AcctConfirmation.Controllers
{
    public class AcctConfirmationController : Controller
    {
        //
        // GET: /AcctConfirmation/

        public ActionResult Index()
        {
                return View();
        }

        public ActionResult AcctSearch(string test)
        {
            var accts = LoadGridViewModel.GetAcctCodesList(test);
            return View(accts);       
        }


    }
}


my views: index
C#
<div id="dialog" class="web_dialog">
        <table style="width: 100%; height: 100%">
        <tr>
            <td>
              @Html.LabelFor(model => model.AccountCode)
            </td>
            <td>
              @Html.TextBoxFor(model => model.AccountCode)         
                  @Html.ActionLink("search", "AcctSearch", "AcctConfirmation", null, new
             {
                 @class = "openDialog",
                 data_dialog_id = "searchDialog",
                 data_dialog_title = "Account Code"
             })
                    @*<a href="/AcctConfirmation/AcctSearch">search</a>*@
            </td>
            <td>
              @Html.LabelFor(model => model.CustDateConfirmed)
            </td>
            <td>
              @Html.TextBoxFor(model => model.CustDateConfirmed, new { style = "width: 95%;" })
            </td>            
        </tr>
        </table>
</div>


my views: AcctSearch
C#
@{
    ViewBag.Title = "Account Code";
    Layout = null;
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSearch").click(function (e) {
            var testData = $("#txtSearchkey").val();
            $.get("/AcctConfirmation/AcctSearch", { "test": testData }, function (data) { });
        });
    });
</script>


@using (Html.BeginForm())
{
    <div>
    <table>
      <tr>
        <td>
           Search Key:
        </td>
        <td>
            <input id="txtSearchkey" type="text" />
        </td>
        <td>
            <input id="btnSearch" type="button" value="Filter" />
        </td>
      </tr>        
    </table>
    </div>
    

    <div id="gridDetails">

        <table border=2 style="width: 100%; height: 100%">    
            <tr>
              <td>
                <table id="myDataTable" class="display">
                    <thead>
                        <tr>
                            <th>Company name</th>
                            <th>Address</th>
                            <th>Town</th>
                        </tr>
                    </thead>

                    <tbody>
                            @if (Model != null)
                            {
                                foreach (var Acct in Model)
                                {
                                <tr>
                                    <td>@Acct.AcctCode</td>
                                    <td>@Acct.CustName</td>
                                    <td>@Acct.CustAddress</td>
                                </tr>
                                }
                            }

                    </tbody>
                </table>
              </td>
            </tr>
        </table>
    </div>
}


my viewmodel: LoadGridViewModel
C#
namespace AcctConfirmation.ViewModel
{
    public class LoadGridViewModel
    {
        
        public static IList<AcctConfirmationPopup> AcctData = null;
        public static IList<AcctConfirmationPopup> GetAcctCodesList(string tmpSearched)
        {
            AcctData = new List<AcctConfirmationPopup>();
            if ((tmpSearched != "") && (tmpSearched != null))
            {                
                

                using (var db = new dbSIEntities())
                {
                    var Acct = from b in db.tblAR
                               where (b.AcctCode.ToLower().Contains(tmpSearched.ToLower()) || b.CustName.ToLower().Contains(tmpSearched.ToLower()))
                               select b;

                    foreach (var accts in Acct)
                    {
                        AcctData.Add(new AcctConfirmationPopup() {AcctCode = accts.AcctCode, CustName = accts.CustName, CustAddress= accts.CustAddress});
                    }
                }
            }
            
            return AcctData;
        }
    }
}
Posted
Updated 6-Sep-12 19:48pm
v2
Comments
Syed Salman Raza Zaidi 7-Sep-12 3:07am    
after if(Model != null) also add an else, seems like you're getting your model null
naijeru 7-Sep-12 3:14am    
Hi Sir Syed,

Thanks for the reply.. actually i tried to use break-point and check my codes every run.. it works properly.. it has data inserted this: foreach (var Acct in Model) but when i look my UI no data appear..

Use:
C#
@model IEnumerable<loadgridviewmodel></loadgridviewmodel>


on top of your view,as you're having IList so you'll have to specify model as IEnmumerable
 
Share this answer
 
Comments
naijeru 7-Sep-12 3:46am    
still.. no data display..
naijeru 7-Sep-12 3:48am    
can i have you e-mail addr? i will send you my codes.. and try it..
Syed Salman Raza Zaidi 7-Sep-12 3:58am    
salmanzaidi87 at gmail
naijeru 7-Sep-12 4:53am    
done sending sir..
Add your solution ><>>>>>>>>>>>[^][^][^][^][^][^][^][^][^][^][^][^][^]here
 
Share this answer
 
my controller:
[HttpPost]
public ActionResult Search(string SearchKey, string BranchCode)
{
    IList<AcctConfirmationPopup> AcctData = null;
    AcctData = new List<AcctConfirmationPopup>();

    if (SearchKey != null)
    {
        using (var db = new dbSIEntities())
        {
            var Acct = from b in db.tblAR
                       where ((b.BranchCode.ToLower().Contains(BranchCode.ToLower())) && (b.AcctCode.ToLower().Contains(SearchKey.ToLower()) || b.CustName.ToLower().Contains(SearchKey.ToLower())))
                       select b;

            foreach (var accts in Acct)
            {
                AcctData.Add(new AcctConfirmationPopup() { AcctCode = accts.AcctCode, CustName = accts.CustName, CustAddress = accts.CustAddress });
            }
        }
    }
    return PartialView("SearchResults", AcctData.ToList());
}


my Partial view:
<div id="searchResults">
    <table id="myDataTable" class="display">
      <thead>
        <tr>
            <th>Account Code</th>
            <th>Customer name</th>
            <th>Address</th>
        </tr>
      </thead>

      <tbody>
        @foreach (var Acct in Model)
        {                          
            <tr>  
            <td>@Acct.AcctCode</td>
            <td>@Acct.CustName</td> 
            <td>@Acct.CustAddress</td> 
            </tr>  
        }
      </tbody>
   </table>
</div>


my view:
@using (Html.BeginForm())
{
    <fieldset id="search">

    <legend>Search Criteria</legend>
        <div>
           <div class="searchOption">
                @Model.BranchCode
                <input id="txtbCode" type="text" value="@Model.BranchCode" style="display:none"/>               
            </div>
           <div class="searchOption">
                @Model.BranchName
            </div>
        </div>
        <div>
            <div class="searchOption">
                <input id="txtSearchkey" type="text" />
            </div>
            <div class="searchOption">
                <input type="hidden" id="StartIndex" value="1" />
                <input id="btnSearch" type="button" value="Filter" />
            </div>
        </div>
    </fieldset> 
}

<div id="searchResults">
    <!-- placeHolder for search results -->
</div>
 
Share this answer
 

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