json - Retuning a JsonResult -
i'm trying return text message box when error occurs , return type jsonresult.
i believe i'm returning valid type, when messagebox appears, says "undefined".
i have json set following:
string maxchars = "upload file size exceeded!"; return json(new { maxcharacters = maxchars });
what doing wrong?
if returning json data httpget action method, should explicitly tell json method allow sending json data request.
public actionresult yourmethod() { string maxchars = "upload file size exceeded!"; return json(new { maxcharacters = maxchars }, jsonrequestbehavior.allowget); }
and in client side code, should accessing maxcharacters
property of response coming ajax call.
$.get("@url.action("yourmethod","yourcontrollername")",function(res){ alert(res.maxcharacters); });
Comments
Post a Comment