Click here to Skip to main content
15,562,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, i have this small question.
When we do post using ajax, i can return boolean type of value using ActionResult type in controller method after success but I cannot return string like 'Success' or other message. Can you guys tell me how can i do that kind of stuff?


Any help would be appreciated.

What I have tried:

I tried something like this



this goes for ajax call in jquery

$.ajax({

    url: "/Employee/SubmitInformation",
    dataType: 'json',
    data: {
        EmployeeID: EmpID,
        EmpName: empName
    },
    type: "POST",
    cache: false,
    success: function (data) {
        //want to return data as not boolean but string here
    },
    error: function (a, b, c) {
       alert("Error")
    }
});




this goes in controller
[HttpPost]
        public ActionResult SubmitInformation(int EmployeeID,string EmpName)
        {
           //after successful entry of information 
           //return success message
           return Json("success", JsonRequestBehavior.AllowGet);

        }
Posted
Updated 13-Apr-17 12:08pm
v2

1 solution

If you want to just return a string literal, in that case you can use Content() :

C#
return Content("success");


and in javascript check the reponse:

JavaScript
success: function (data) {
                if(data == "success")
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900