简体   繁体   中英

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

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

style quote not closed

AND

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM