Click here to Skip to main content
Rate this: bad
good
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>
            <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
@{
    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
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
naijeru542
Edited 6-Sep-12 20:48pm
v2
Comments
Syed Salman Raza Zaidi at 7-Sep-12 3:07am
   
after if(Model != null) also add an else, seems like you're getting your model null
naijeru at 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 at 7-Sep-12 3:46am
   
still.. no data display..
naijeru at 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 at 7-Sep-12 3:58am
   
salmanzaidi87 at gmail
naijeru at 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
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 Jul 2014
Copyright © CodeProject, 1999-2014
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