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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -