I working on mvc asp.net csharp i need to make function return json result when branch code exist then return true and if not exist return false so can you help me do this function return json result true or false
C#
public JsonResult CheckExist(string BranchCode)
{
string branches = _db.Branch.Single(x => x.iBranchCode == BranchCode).iBranchCode.ToString();
// so what i write here to return true or false
}
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jun 5, 2023, 8:22 AM EDT
Hi ahmad
try this code
public JsonResult CheckExist(string BranchCode) { bool isExists = _db.Branch.Any(x => x.iBranchCode == BranchCode); return Json(new { result = isExists }, JsonRequestBehavior.AllowGet); }Amit MohantyRank #112 · 20K reputationPosted Jun 5, 2023, 8:54 AM EDT
public JsonResult CheckExist(string BranchCode) { bool branchExists = _db.Branch.Any(x => x.iBranchCode == BranchCode); // Create an anonymous object with the 'exists' property var result = new { exists = branchExists }; // Return the result as JSON return Json(result); }Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 5, 2023, 12:02 PM EDT
public JsonResult CheckExist(string BranchCode) { bool exists = _db.Branch.Any(x => x.iBranchCode == BranchCode); return Json(new { result = exists }, JsonRequestBehavior.AllowGet); }