Introduction
Controller
First, we create a new project using Visual Studio. Choose Project template MVC. Now, we create a Controller. Controller has two action methods, mentioned below:
- Action method for handling the GET operation.
Inside this Action method, only the view is returned.
- Action method for handling POST operation.
This Action method handles the form submission and it accepts the value of the form element as a parameter.
The name value fetched from the Form collection and the current Server date and time is set to a ViewBag object named “Message”.
Controller Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace AlertMessge.Controllers
- {
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Index(string name)
- {
- ViewBag.Message = String.Format("Hello{0}.\\ncurrent Date and time:{1}", name, DateTime.Now.ToString());
- return View();
- }
- }
- }


Former memberPosted Feb 23, 2020, 9:49 AM
Rofl now that is crap
mudassar khanPosted Dec 21, 2019, 1:34 PM
Copied from ASPSnippets.com https://www.aspsnippets.com/Articles/ASPNet-MVC-Display-Message-from-Controller-in-View-using-JavaScript-Alert-MessageBox.aspx
imran osmanzaiPosted Jan 6, 2018, 1:15 AM
Good job dear brother very help full for me
Syed ShanuPosted Oct 26, 2016, 7:56 PM
Good Start keep writing more.
Anu VPosted Oct 26, 2016, 1:18 AM
Nice..