使用MVC3剃刀填充表 [英] populate table using MVC3 razor

查看:76
本文介绍了使用MVC3剃刀填充表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





有谁可以帮助我了?以下是我的代码。我的桌子的数据不会显示。

请帮助它正常运行,没有错误。



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);       
        }


    }
}





我的观点:index



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>





我的观点:AcctSearch



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





我的viewmodel:LoadGridViewModel



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;
        }
    }
}

推荐答案

(document).ready(function(){
(document).ready(function () {


#btnSearch)。click(function(e) ){
var testData =
("#btnSearch").click(function (e) { var testData =


#txtSearchkey)。val();
("#txtSearchkey").val();


这篇关于使用MVC3剃刀填充表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆