jquery and mvc.net query

本文关键字:query net mvc and jquery | 更新日期: 2023-09-27 18:10:13

我是全新的mvc.net nhibernate和编程,我想做的是使用ajax请求查询…我有两页…第一页连接到SQL server中的一个表,下一页连接到另一个表…这两个表通过外键连接…第一页将显示从第一个表的jquery数据表记录,它有链接称为视图,当我点击它,它会引导我到其他控制器/页面,这将显示其他db表的所有的jquery数据表记录..所以我的问题是我怎么能查询下一个表(页),当我点击视图(第一页/表)?我想展示一些记录……我应该通过什么考试?我真的很困惑……这里是我的类模型:

public class Pybkhdr : NhibernateModel, IMcDataParameter
{
    public virtual Guid ID { get; set; }
    public virtual string PayeeCode{ get; set; }
    public virtual string PayeeName { get; set; }
    public virtual DateTime PaymentDate { get; set; }
    public virtual string BankName { get; set; }
    public virtual string FileName { get; set; }
    public virtual string FileStatus { get; set; }
    public virtual int TotalRecord { get; set; }
    public virtual decimal TotalAmount { get; set; }
    public virtual string HashTotal { get; set; }
    public virtual int Acti { get; set; }
    public virtual string Crid { get; set; }
    public virtual DateTime Crdt { get; set; }
    public virtual string Lmid { get; set; }
    public virtual DateTime Lmdt { get; set; }
}
public class Pybkdtl : NhibernateModel, IMcDataParameter
{
    public virtual Guid ID { get; set; }
    public virtual Guid PybkhdrId { get; set; }
    public virtual int SequenceNo{get; set;}
    public virtual string CustomerName { get; set; }
    public virtual string Icno { get; set; }
    public virtual decimal Amount { get; set; }
    public virtual string AccountNo { get; set; }
    public virtual string ReferenceNo { get; set; }
    public virtual string TransactionRef { get; set; }
    public virtual string MobileNo { get; set; }
    public virtual string Channel { get; set; }
    public virtual DateTime TransactionDate { get; set; }
    public virtual string TransactionStatus { get; set; }
    public virtual int Acti { get; set; }
    public virtual string Crid { get; set; }
    public virtual DateTime Crdt { get; set; }
    public virtual string Lmid { get; set; }
    public virtual DateTime Lmdt { get; set; }

视图:

@using Cp.Controllers
@using ld.Http
@{
    ViewBag.Title = "Bank Payment Listing";
    Layout = Request.IsAjaxRequest() ? "" : "~/Views/Shared/_DpLayout.cshtml";
}
<style>
    .displaynone {
        display: none;
    }
</style>
@Html.Raw(ViewBag.Script)
<fieldset>
    <div>
        <table class="table1pxForDt" style="width:100%">
            <tr>
                <td>
                    Approved - Pending payment Approved<br />
                    Error - One or more matching having problem<br />
                    Match - All transaction match<br />
                    New - only upload no do any matching<br />
                    Unmatch - One or more transaction cannot match
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: left;">
        <div style="text-align: right;">
            <input type="button" onclick="BackHomePage()" value="Back" />
            <input type="button" name="btnupload" id="btnupload" value="Upload New File" />
        </div>
        Search:<input value="" id="SearchValue" onkeydown="if (EnterSearch('SearchValue', event)) { $('#btnSearch').click(); }" />
        Field:<select id="SearchType" style="margin-right:20px;">
                  <option value="FileName" selected="selected">File Name</option>
                  <option value="BankName">Bank</option>
              </select>
        Status : <select id="SearchStatus">
                     <option value="">-- Select --</option>
                     <option value="@BankPaymentController.PayFileStatus.Approved">Approved</option>
                     <option value="@BankPaymentController.PayFileStatus.Error">Error</option>
                     <option value="@BankPaymentController.PayFileStatus.Match">Match</option>
                     <option value="@BankPaymentController.PayFileStatus.New">New</option>
                     <option value="@BankPaymentController.PayFileStatus.Unmatch">Unmatch</option>
                 </select>
        <input type="button" id="btnSearch" name="btnSearch" value="Search" />
        <table class="table1pxForDt" id="dtbankpayheader" style="width:100%">
            <thead>
                <tr>
                    <th>Status</th>
                    <th>Upload Date</th>
                    <th>File Name</th>
                    <th>Bank</th>
                    <th>Upload By</th>
                    <th>filepath</th>
                    <th>summarypath</th>
                    <th>ACTION</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</fieldset>
<script type="text/javascript">
    var urlroot = '@(Url.Content("~/"))';
    $(document).ready(function () {
        ld.nf.RemoveModuleMask("workbody");
        if (ld.gd('#ScreenTitleId'))
            ld.gd("ScreenTitleId").innerHTML = '@ViewBag.Title';
    });
    $('#btnSearch').click(function () {
        mydatatable.fnDraw();
    });
    $('#btnupload').click(function () {
        window.location = "@("/BankPayment/BankPaymentUpload".UrlResolve())";
    });
    function BackHomePage() {
        window.location = "@("/MainWork/Welcome".UrlResolve())";
        ld.gd("ScreenTitleId").innerHTML = "";
    }
    function DeleteFile(filename) {
        alert(urlroot + 'BankPayment/BankPaymentDelete?fn=' + filename + '&fc=' + Math.random());
        window.location = urlroot + 'BankPayment/BankPaymentDelete?fn=' + filename + '&fc=' + Math.random();
    }
    function EnterSearch(textId, evt) {
        if (textId != undefined && evt != undefined) {
            ld.gd(textId).setAttribute("autocomplete", "off");
            var myEvent = evt ? evt : (window.event ? window.event : null);
            if (myEvent.keyCode === 13) {
                return true;
            }
        }
        return false;
    }
    var mydatatable = null;
    $(document).ready(function () {
        mydatatable = $('#dtbankpayheader').dataTable({
            "oLanguage": {
                "sUrl": "@(Resources.AppGlobal.JqDataLabelFile.UrlResolve())"
            },
            "aaSorting": [[1, "desc"]],
            "bStateSave": true,
            "aLengthMenu": [[10, 25, 50], [10, 25, 50]],
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "bPaginate": true,
            "bProcessing": false,
            "bServerSide": true,
            "sAjaxSource": "@("/BankPayment/BankPaymentListingAction".UrlResolve())" + "?urlrnd=" + Math.random(),
            "sServerMethod": "POST",
            'bLengthChange': true,
            "iDisplayLength": 30,
            "bFilter": false,
            "fnServerData": function (sSource, aoData, fnCallback) {
                aoData.push({ 'name': 'SearchValue', 'value': ld.gd("SearchValue").value });
                aoData.push({ 'name': 'SearchType', 'value': ld.gd("SearchType").value });
                aoData.push({ 'name': 'SearchStatus', 'value': ld.gd("SearchStatus").value });
               // aoData.push({ 'name': 'ID', 'value': '@(ViewBag.ID)' });
                    $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": function (data) {
                        fnCallback(data);
                    }
                });
            },
            "aoColumns": [
                { "sName": "FileStatus", "sClass": "left", "sWidth": "100px" },
                { "sName": "Crdt", "sClass": "left", "sWidth": "100px", "sType": "date" },
                { "sName": "FileName", "sClass": "left" },
                { "sName": "BankName", "sClass": "left", "sWidth": "100px" },
                { "sName": "Crid", "sClass": "left", "sWidth": "150px" },
                { "sName": "filepath", "sClass": "left", "sWidth": "10px", "bVisible": false },
                { "sName": "summarypath", "sClass": "left", "sWidth": "10px", "bVisible": false },
                {
                    "sName": "",
                    "sWidth": "100px",
                    "bSearchable": false,
                    "bSortable": false,
                    "fnRender": function (oObj) {
                        var urlreturn = '';
                        if ($.trim(oObj.aData[5]).length > 0 || $.trim(oObj.aData[6]).length > 0 || $.trim(oObj.aData[2]).length > 0) {
                            if ($.trim(oObj.aData[5]).length > 0) {
                                urlreturn = '<a href="' + urlroot + oObj.aData[5] + '" target="_blank" >LOG</a>&nbsp;&nbsp;';
                            }
                            if ($.trim(oObj.aData[6]).length > 0) {
                                urlreturn = urlreturn + '<a href="' + urlroot + oObj.aData[6] + '" target="_blank" >SUMMARY</a>&nbsp;&nbsp;';
                            }
                            if ($.trim(oObj.aData[0]) == 'NEW' && $.trim(oObj.aData[2]).length > 0) {
                                urlreturn = urlreturn + '<a href="#" onclick="DeleteFile(''' + $.trim(oObj.aData[2]) + ''');" >DELETE</a>&nbsp;&nbsp;';
                            }
                        } else {
                            urlreturn = '<span>&nbsp;&nbsp;</span>';
                        }
                        urlreturn += " | <a href='@("/BankPaymentDetail/BankPaymentListing".UrlResolve())? ' >view</a>";
                       // ?id=
                        return urlreturn;             
                    }
                }
            ],
            "fnPageingChange": function (a) {
                alert(a);
            }
        });
    });
</script>

jquery and mvc.net query

在第一个表中添加一个操作链接。在该动作链接的参数中添加对象的id。动作链接指向一个控制器方法,该方法将加载第二个页面(将模型作为视图的参数传递)。你的第二个页面/视图将只显示传入参数的模型。

[编辑]

在你的第一个表视图中,你想添加一个链接来显示你的第二个表,你使用:

@Html.ActionLink("View details", "MethodToShowTheView", "ControllerThatWillHandleTheQuery", null, new { @id = [Here you put the ID of the object displayed in the first table]});

在你的"ControllerThatWillHandleTheQuery"中,你必须创建一个名为"MethodToShowTheView"的方法:

[HttpGet]
public ActionResult MethodToShowTheView(string id)
{
    var guid = //Convert string to GUID
    var model = //Look for the Details for this id and load in this variable
    return View("YourSecondView", model);
}

你必须有一个名为"YourSecondView"的第二个视图。在其中,您必须使用视图头部的这一行设置传递的模型类型:

@model [TypeOfTheModel];

然后在您的页面中,您只需要使用变量Model显示数据。例如:

@{
    @Html.Raw(Model.Id);
}
[Edit2]

    urlreturn += " | <a href='@("/BankPaymentDetail/BankPaymentListing".UrlResolve())?id=" + oObject.aData[indexOfTheId] + "' >view</a>";

它将在控制器BankPaymentDetail中调用BankPaymentListing方法,并在url中传递id。然后,您可以使用控制器获取要显示的详细数据,并调用模型中包含详细数据的第二个视图。

也许我没有完全理解这个问题。

我可以引导你看到javascript MVC网格,我用它来格式化和显示数据。