1

I need to populate Kendo grid from search button. I write personal ID and I should get other information in the grid, but after writing the ID in the textbox and clicking search, I get

"Server was unable to process request. ---> Procedure or function 'PROS_CRA_PUBLIC_GET_DOCUMENT_LIST_BY_PN' expects parameter '@PN', which was not supplied."

Controller

public ActionResult Search(string personalID, [DataSourceRequest]DataSourceRequest request)
    {



        var serviceclient = new PersonalInfoServiceClient();
        DataSourceResult result = null;
        try
        {
            var items = serviceclient.GetRegistryInfoForPerson(personalID);
            result = items.ToDataSourceResult(request);

        }
        catch 
        {
            throw;
        }
        finally
        {
            serviceclient.Close();
        }

        return Json(result, JsonRequestBehavior.AllowGet);

    }

View (part of it)

 <div id ="search">
@using (Html.BeginForm("Search", "Main")){    
     <p> personal number: <input type="text" name="Searchtext" id="SearchString" /> <input type="submit" value="search" name="btnSearch" id="btnSearch" /></p> 
    }

<div id="civil">
@(Html.Kendo().Grid<PersonalIDCheckerMvCKendo.Models.PersInfo>()   
.Name("Grid")
.AutoBind(false)
.Columns(columns =>
{
    //columns//    })
.Groupable()
.Sortable()
.Scrollable()   
.Filterable()
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(c=> c.personalID))
    .Read(read => read.Action("Search", "Main").Data("test"))
)
)
</div>

<script>
$("#btnSearch").on('click', function test() {

console.log("click");
var searchText = $("#SearchString").val();

if (searchText == "") {

alert("You must enter a search value");
return;
}

$.ajax({
    url: '@Url.Action("Search","Main")',
    data: { personalID: searchText},
    type: 'POST',
    dataType: "json",
    success: function(result) {
var grid = $('#Grid').getKendoGrid(); 
grid.dataSource.data(result);
grid.refresh();
        }
    });
});
    </script>

Model

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using DataAnnotationsExtensions;

namespace PersonalIDCheckerMvCKendo.Models
{
[DataContract(IsReference=true)]
public class PersInfo
{
    [DataMember]
    [DisplayName("Personal#")]
    public string personalID
    {
        get
        {
            return _PersonalID;
        }

        set
        {
            if (_PersonalID != value)
            {
                _PersonalID = value;
            }
        }
    }
    private string _PersonalID;

    [DataMember]
    [DisplayName("Name")]
    public string FirstName
    {
        get
        {
            return _FirstName;
        }

        set
        {
            if (_FirstName != value)
            {
                _FirstName = value;
            }
        }
    }
    private string _FirstName;

    [DataMember]
    [DisplayName("Lastname")]
    public string LastName
    {
        get
        {
            return _LastName;
        }

        set
        {
            if (_LastName != value)
            {
                _LastName = value;
            }
        }
    }
    private string _LastName;

//etc

thanks

4

2 回答 2

1

您没有通过personalID

添加一个 javascript 函数,该函数将负责传递控制器函数所需的数据,例如

function additionalData() {
    return {
        personalID: '@Model.personalID'
    };
}

然后更改网格的 DataSource 以使用 javascript 函数

.DataSource(dataSource => dataSource.Ajax().ServerOperation(false)
    .Read(read => read.Action("Search", "Main")                                                                                      
    .Data("additionalData"))
)

还要确保

[DataSourceRequest]DataSourceRequest 请求

参数首先放在你的控制器函数中,例如

public ActionResult Search([DataSourceRequest]DataSourceRequest request
                           , string personalID)

还要确保您将网格的列与返回的对象的属性绑定(在您的情况下为 PersonalIDCheckerMvCKendo.Models.PersInfo)。例如

.Columns(columns =>
     {
          columns.Bound(pi => pi.Name);
          columns.Bound(pi => pi.Surname);
          // Some other columns.                                    
     })

*更新

为了帮助您,我添加了一个工作网格示例。这是我的网格

@(Html.Kendo().Grid<ClientSearchResult>()
    .Name("Grid")
    .HtmlAttributes(new {style = "height:400px; cursor:pointer"})
    .DataSource(dataSource => dataSource.Ajax().ServerOperation(false)
        .Read(read => read.Action("RefreshGrid", "Client")                                                                                                 
        .Data("additionalData"))
        .PageSize(20)
    )
    .Columns(columns =>
    {
        columns.Bound(c => c.ClientId);
        columns.Bound(c => c.Name);
        columns.Bound(c => c.PolicyNumber);
        columns.Bound(c => c.ClaimNumber);
        columns.Bound(c => c.Status);
        columns.Bound(c => c.IsCompany);
    })
    .Pageable(page => page.Enabled(true).PageSizes(new[] {10, 20, 30, 40}))
    .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
    .Scrollable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
    .Events(events => events.Change("grid_selected"))
)

我的javascript函数

function additionalData() {
    return {
        cellNumber: '@Model.CellNumber',
        name: '@Model.Name',
        policyNumber: '@Model.PolicyNumber',
        claimNumber: '@Model.ClaimNumber',
        brokerCode: '@Model.BrokerCode',
        brokerName: '@Model.BrokerName'
    };
}

和我的控制器功能

public ActionResult RefreshGrid([DataSourceRequest] DataSourceRequest request
                                , string cellNumber, string name 
                                , string policyNumber, string claimNumber
                                , string brokerCode, string brokerName)
{
    if (cellNumber == string.Empty && name == string.Empty && policyNumber ==   
        string.Empty && claimNumber == string.Empty && brokerCode == string.Empty &&   
        brokerName == string.Empty)
            return Json(new List<ClientSearchResult>());
        else
        {
            List<ClientSearchResult> searchResult =   
            ClientMaintenance.ClientSearch(cellNumber, name, policyNumber, claimNumber,        
                                           brokerCode, brokerName).ToList();
            var result = searchResult.ToDataSourceResult(request);
            return Json(result);
        }
}
于 2013-11-07T12:41:43.037 回答
0

我修好了它

将控制器更改为:

    public ActionResult Search([DataSourceRequest]DataSourceRequest request, string searchString)
    {



        var serviceclient = new PersonalInfoServiceClient();
        DataSourceResult result = null;
        if (!String.IsNullOrEmpty(searchString))
        {
            try
            {
                var items = serviceclient.GetRegistryInfoForPerson(searchString);
                result = items.ToDataSourceResult(request);

            }

            catch
            {
                throw;
            }

            finally
            {
                serviceclient.Close();
            }
        }

        return Json(result, JsonRequestBehavior.AllowGet);

    }

看法 :

文本框:

@Html.TextBox("SearchString")

功能:

<script type="text/javascript">
$(document).ready(function(){
    $("#btnSearch").click(function (e) {
     $.ajax({
            url: '@Url.Action("Search","Main")',
            type: 'POST',
            dataType: "json",
            success: function (result) {    

                $("#Grid").data("kendoGrid").dataSource.read();
                $("#Grid").data("kendoGrid").refresh();
                e.preventDefault();
            }
于 2013-12-03T07:13:29.580 回答