Hi nabilabolo,
Use TempData object. Refer below sample code.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult Attachment()
{
return View();
}
[HttpPost]
public ActionResult Attachment(HttpPostedFileBase files)
{
if (files != null)
{
//save database in the database
return RedirectToAction("Attachment", "Home");
}
else
{
TempData["Message"] = "Please Insert Certificate Record!";
return RedirectToAction("Index", "Home");
}
}
}
View
Index
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@using (Html.BeginForm("Attachment", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<span>Select File:</span>
<input type="file" name="files" />
<input type="submit" value="Upload" />
}
@if (TempData["Message"] != null)
{
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert("@TempData["Message"]");
});
</script>
}
</body>
</html>
Attachment
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Attachment</title>
</head>
<body>
</body>
</html>
Screenshot