Milos Mijatovic
Milos Mijatovic

Reputation: 985

MVC3 partial view with ajax returning only JSON

I am new to web programming and i am learning MVC, ajax, jQuery, etc, plus i am using some controls from telerik.

And I am stuck at one particular point.

I have a partial view which only purpose is to show a list of uploaded files in telerik grid. And it renders fine when i am loading page for the first time. I do it like this:

@Html.Partial("~/Views/Document/Lista.cshtml", Model.Files)

But, upon completion of ajax file upload, i would like to update specific div with that partial view with an ajax call:

$("#List").load("/Document/List/", { id: fk });

I am inclined to use POST call because telerik grid requires some data in json format, and json doesn't work well with GET.

Now this is my controller action:

[GridAction][HttpPost]
public ActionResult List(int id)
{
    Document doc = db.Documents.Where(d => d.ID == id).Single();
    return PartialView("~/Views/Document/List.cshtml", new GridModel(doc.Files));
}

And now, this will result in json ONLY. Once again, when I render it for the first time, everyting is ok, so the view should't be the culprit. I am looking at the response in fiddler and it looks something like this:

{"data":[{"ID_File":54,"FK_Document":2,"FileName":"ckeditor_3.6.2.zip","FileType":"application/zip","FileData":null,"FileSize":2294443,"UploadingUser":null},{"ID_File":63,"FK_Document":2,"FileName":"254371_DropDownInGrid-CL.zip","FileType":"application/zip","FileData":null,"FileSize":1708740,"UploadingUser":"S-1-5-21-3024387492-927407738-3508986423-513"}],"total":14}

Just like this, no HTML whatsoever.

I tried playing with various options in my action method like changing return type to JSON, or returning whole view instead of partial but i always get same result: bare JSON.

I googled it, but couldn't find similar problem nowhere...

So, I am asking your help.

Upvotes: 1

Views: 907

Answers (1)

SadullahCeran
SadullahCeran

Reputation: 2415

You may want to consider refreshing telerik grid without dealing with json stuff. See: http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#rebind

Upvotes: 1

Related Questions