samedi 9 mai 2015

Pass Stringbuilder message from Json [MVC-Controller]and render it in view

I am trying to pass a StringBuilder message as an extra data back to ajax call but I am failing to manipulate it in client side. Below is the way I append message to StringBuilder and pass it back.

StringBuilder retMessage=new StringBuilder();
retMessage.Clear().AppendLine("Successfully added the user!"); 
//Clear will done only on Success otherwise will append the different errorMessage using AppendLine
return Json(new { result = valid, message = retMessage });

On the ajax Success I tried retrieving it as below but with no success.

 success: function (data) {
              if (data.result) {
                    ResetForm('#frmChangePwd');
                    console.log(data.message);
              },
 }

Below are images showing how it is passed from server side and how it is obtained in client side!!

Server Side return

Server Side return

Client Side retrieval

Client Side retrieval

Can anyone tell me how to retrieve message in client side and display it in view?

Aucun commentaire:

Enregistrer un commentaire