Deserialisation issues for MVC ComboBox Server Control

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    2 posts
    Member since:
    Feb 2016

    Posted 10 Mar Link to this post

     

    Hello,

     

    I have been unable to solve this issue for the past 2 days and now need some help.

    I am using an Ajax request, to load a partial view, containing two kendo server components bound to my model.

    The JavaScript:

    01.$.ajax({
    02.    type: 'POST',
    03.    url: '/JobEnquiry/GetData',
    04.    data: {
    05.        periodNo: selectedPNo
    06.    },
    07.    beforeSend: function () { /*alert("before send");*/ },
    08.    success: function (data) {
    09.        $("#JobEnquiryContentArea").html(data);
    10.        $("#JobEnquiryContentArea").show();
    11.    },
    12.    error: function (jqXHR, textStatus, errorThrown) {
    13.        //$('#mnuNav').html(jqXHR.responseText);
    14.        LSViewer.ShowErrorDialog(jqXHR.status, jqXHR.statusText, jqXHR.responseText, errorThrown);
    15.    },
    16.    complete: function () { /*alert("complete");*/ }
    17.});

     

    The Model:

    01.public class JobEnquiryDetailsModel
    02.{
    03.    public IEnumerable<JobListModel> JobList { get; set; }
    04.    public string Message { get; set; }
    05.    public string Branch { get; set; }
    06.    public IEnumerable<SelectListItem> jobSelection { get; set; }
    07.    [DisplayName("Period")]
    08.    public string selectedPeriod { get; set; }
    09.    [DisplayName("Job No")]
    10.    public string selectedJob { get; set; }
    11. 
    12.}

    and for completion The JobListModel:

    01.public class JobListModel
    02.{
    03.    public string JobNumber { get; set; }
    04.    public string ClientReference { get; set; }
    05.    public string JobName { get; set; }
    06.    public DateTime Opened { get; set; }
    07.    public string ProjectManager { get; set; }
    08.    public string JobType { get; set; }
    09.    public decimal OriginalValue { get; set; }
    10.    public decimal BudgetCosts { get; set; }
    11.    public decimal BudgetProfit { get; set; }
    12.    public decimal ContractValue { get; set; }
    13.    public decimal ForecastValue { get; set; }
    14.    public decimal CostToComplete { get; set; }
    15.    public string WorkOrder { get; set; }
    16.    public string Branch { get; set; }
    17.    public string ClosedFlag { get; set; }
    18.    public string CreatedUser { get; set; }
    19.    public string SiteCode { get; set; }
    20.    public string ClientName { get; set; }
    21.    public string ClientCode { get; set; }
    22.}

    The Controller method:

    01.[HttpPost]
    02.public ActionResult GetData(string periodNo)
    03.{
    04.    JobEnquiryDetailsModel myModel = new JobEnquiryDetailsModel();
    05.    DownloadJobData(periodNo);
    06.    List<JobListModel> jobsList = MapJobJistData();
    07. 
    08.    myModel.Branch = "";
    09.    myModel.JobList = jobsList;
    10.    myModel.Message = "I Fetched some data....";
    11.    myModel.selectedJob = "";
    12.    myModel.selectedPeriod = periodNo;
    13.    PartialViewResult mr;
    14.    return PartialView("_JobEnquiryDetails",myModel);
    15.}

    And lastly my partial View:

    01.@model Models.JobEnquiryDetailsModel
    02. 
    03.<div id="displayParameters" class="row clearfix">
    04.    <div class="col-lg-3">
    05.        @(Html.LabelFor(model => model.Branch))
    06.        @(Html.Kendo().TextBoxFor(model => model.Branch)
    07.            .HtmlAttributes(new { style = "width: 80px;" })
    08.        )
    09.    </div>
    10.    <div class="col-lg-3">
    11.    @(Html.LabelFor(model => model.selectedJob))
    12.    @(Html.Kendo().ComboBoxFor(model => model.selectedJob)
    13.                .DataTextField("JobNumber")
    14.                .DataValueField("JobNumber")
    15.                .BindTo(Model.JobList)
    16.                .HtmlAttributes(new { style = "width: 120px;" })
    17.    )
    18.    </div>
    19.    <div class="col-lg-6">
    20.    </div>
    21.</div>
    22.<div id="enquiryContent" class="row clearfix">
    23.    <div class="col-lg-5 pull-left">
    24.        LEFT HAND SIDE
    25.    </div>
    26.    <div class="col-lg-7 pull-right">
    27.        RIGHT HAND SIDE
    28.    </div>
    29.</div>

    K. Now all that is in, the error is:

    1.System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

    I have read numerous pieces of help on JsonSerialisers, however after trying, none are helping in my particular case.

    I suspect it is because I am returning a partial view which is not json, then the kendo server object is doing something under the hood to the model data and boom.

    The List I am Binding to is only 17000 odd items, which while large isn't obscene.

    Really running out of ideas.

    Any assistance appreciated.

  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 14 Mar Link to this post

    Hello Andrew,

    The reason for the experienced issue might be related with specified in your web.config decreased length of the maxJsonLength
    Please try to increase the json length from your web.config in the following manner:

    <system.web.extensions>
            <scripting>
                <webServices>
                    <jsonSerialization maxJsonLength="2147483647" />
                </webServices>
            </scripting>
        </system.web.extensions>

    Hope this would help.

    Regards,
    Nencho
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top