You can use Model,ViewData,ViewBag,TempData for send data to view. I prefer ViewData for your requirement as its type is dynamic. In your code you used ViewBag and though is not working, you commented out ViewBag.
Actually it will work when you use View(YourViewName) method for return ActionResult. If you use RedirectToAction method then it actually use 2 separate request so ViewData/ViewBag value will be lost. If you still need to use ReDirectToAction then you should send data to view with the help of TempData object.
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
TempData["Hello"] = "Good Morning???";
return RedirectToAction("About");
}
<div>@TempData["Hello"]</div>
I prefer you use
public ActionResult Validateuser()
{
Login objLogin = new Login();
int intUser = objLogin.validateUser();
ViewBag.Msg = "Invalid User";
return View("About");
}
Please visit
Link