Click here to Skip to main content
12,077,911 members (47,697 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# table MVC3 Razor
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.

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
<div id="dialog" class="web_dialog">
        <table style="width: 100%; height: 100%">
        <tr>
            <td>
              @Html.LabelFor(model => model.AccountCode)
            </td>

my views: AcctSearch
@{
    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>

my viewmodel: LoadGridViewModel
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 6-Sep-12 20:46pm
naijeru546
Edited 6-Sep-12 20: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..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

on top of your view,as you're having IList so you'll have to specify model as IEnmumerable
  Permalink  
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..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Add your solution ><>>>>>>>>>>>[^][^][^][^][^][^][^][^][^][^][^][^][^]here
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 21 Jul 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100