1

When using Ajax in ASPNET MVC, I have 4 options to get view result at least (attached code below).

As a result, Which should I use over the other ones? In the case of the large data, I don't want to get the error msg like

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

Note that, the Json option (3 or 4) can give us "Binding on the client-side is going to be faster than the performance hit of the extra network hit" benefits aspect as this answer said.


  1. PartialView - HttpGet
    [HttpGet]
    [AjaxRequest]
    public PartialViewResult GetTemporaryInvoices(GetTemporaryInvoicesCriteria criteria)
    {
        var data = _multipleInvoicesGenerationService.GetTemporaryInvoices(criteria);
        return PartialView("~./InvoicesTable_Content.cshtml", data);
    }
  1. PartialView - HttpPost
    [HttpPost]
    [AjaxRequest]
    public PartialViewResult GetTemporaryInvoices(GetTemporaryInvoicesCriteria criteria)
    {
        var data = _multipleInvoicesGenerationService.GetTemporaryInvoices(criteria);
        return PartialView("~./InvoicesTable_Content.cshtml", data);
    }
  1. Json - HttpGet
    [HttpGet]
    [AjaxRequest]
    public JsonResult GetTemporaryInvoices(GetTemporaryInvoicesCriteria criteria)
    {
        var jsonData = _multipleInvoicesGenerationService.GetTemporaryInvoices(criteria);
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }
  1. Json - HttpPost
    [HttpPost]
    [AjaxRequest]
    public JsonResult GetTemporaryInvoices(GetTemporaryInvoicesCriteria criteria)
    {
        var jsonData = _multipleInvoicesGenerationService.GetTemporaryInvoices(criteria);
        return Json(jsonData);
    }
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56

1 Answers1

1

If u use multiple actions from your view page then go for Json - HttpGet (option 3). This will help you to get the data without reloading the view page and get the data from the server-side. I have used this before for getting a large number of data but you should improve your LINQ getting data method on the manager.

NB: In the localhost run, it looks slower but when you put your solution on the production server then it will be faster than before.