1

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

1
  • welcome to stack. great frst question. Commented Feb 7, 2013 at 11:34

1 Answer 1

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

style quote not closed

AND

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

Sign up to request clarification or add additional context in comments.

6 Comments

serializing the right way is where i see most confusion on SO MVC Q's. +1
How can I return content when I am using JsonResult
use ActionResult in you signature. Content is the correct return type.
If I used ActionResult I am unable to validate Remote validation and also not getting the o/p as per required
As you said I missed the close tag for style which works even you missed that return Json("<span style='color:Red;'> Username in use</span>",JsonRequestBehavior.AllowGet);
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.