Learner
Learner

Reputation: 351

MVC4 Html formatted string in JSON result

Hi all I have written a sample code to check an user available with the given name, if available I would like to display the text with Red color saying Username in use, for this I have written as follows but the text is not showing

[OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
    public JsonResult IsUserNameAvailable(string UserName)
    {
        var usrAvailable = db.tblUsers.Where(p => p.UserName == UserName).Select(img => img.UserName).FirstOrDefault();

        if (usrAvailable == null)
        {
            return Json("Username is available", JsonRequestBehavior.AllowGet);
        }
        return Json("<span style='color:Red;> Username in use</span>", JsonRequestBehavior.AllowGet);

    }

Can some one help me

Upvotes: 1

Views: 597

Answers (1)

webdeveloper
webdeveloper

Reputation: 17288

"<span style='color:Red;> Username in use</span>"

style quote not closed

AND

return Json() could be raplaced with return Content()

Upvotes: 1

Related Questions