0

I learn ASP.NET MVC and have some issue.

I create two links by ajax helper method in view. They send mailsType argument and response json data. Here is the code of links and AjaxOptions object

    <div class="list-group" style = "text-align: center; margin-top: 10px;">
            @Ajax.ActionLink("Incoming", "GetMails", new { mailsType = State.Incoming }, opts,
                new{@class = "list-group-item active", data_type = "Incoming"})

            @Ajax.ActionLink("Outgoing", "GetMails", new {mailsType = State.Outgoing}, opts,
                new { @class = "list-group-item", data_type = "Outgoing" })
    </div>

Here is ajaxoption, using in ajax helpers

    AjaxOptions opts = new AjaxOptions
{
    OnSuccess = "viewMail",
};

I handle response by javascript function

    function viewMail(data) {
var html =
    '<table class="table table-hover table-striped">' +
        '<thead>' +
        '<tr><th>' + (data.State == 'Incoming' ? 'From' : 'To') + '</th> <th>Subject</th> <th>Date</th></tr>' +
        '</thead>' +
        '<tbody>';

$(data.Mails).each(function(i, el) {
    html += '<tr><td>' + el.From + '</td> <td>' + el.Subject + '</td> <td>' + el.Date + '</td></tr>';
});

html += '</tbody></table>';

$('#contentDiv').html(html);
    }

And here is code of action method in controller

    public ActionResult GetMails(State mailsType)
    {
        if (Request.IsAjaxRequest())
        {
            return Json(new
            {
                State = Enum.GetName(typeof (State), mailsType),
                Mails = _serviceManager.GetMessages(mailsType)
            }, "application/json", JsonRequestBehavior.AllowGet);
        }
        else
        {
            ViewBag.State = Enum.GetName(typeof(State), mailsType);

            return PartialView(_serviceManager.GetMessages(mailsType));
        }

    }

When I use second link all works good, but when I use first one, i have internal server error with code 500 and response type is text/html. I use this links to return partialviews and they all works before.

I tried to use my own ajax request, but result was still the same. I can't understand what's wrong. I understan't that question is abstract, but may be you had same problem or know why it happens.

Edit1

When I write address from link in address bar, I have this error: System.InvalidOperationException: Timeouts are not supported on this stream.

I tryed set big timeout in ajax request, but it didn't help. Reqest executes successfuly when I send less data in response. I think it related with size of data sending in response. Am I wrong? What reasons of this error can be?

I will by happy all yours advice. Thanks to all!

iplot
  • 3
  • 2
  • 2
    It would be helpful to know the text of the error message. Even better, run your website from Visual Studio and have it break on the exception. – esmoore68 Feb 26 '15 at 20:27
  • @esmoore68, thank you. I find my mistake few minutes ago. I try to send a lot of data in response and this was an issue. May be response was timeouted, I don't know. – iplot Feb 26 '15 at 20:35

0 Answers0