Share via

Successful after the button

Harun Ergün 65 Reputation points
2023-01-19T05:44:16.66+00:00

I want to see the text Alert (Successful) after the button is clicked. How should I do ?

Developer technologies | ASP.NET | Other
SQL Server | Other
0 comments No comments

Answer accepted by question author
  1. Lan Huang-MSFT 30,211 Reputation points Microsoft External Staff
    2023-01-19T06:19:04.3666667+00:00

    Hi @Harun Ergün,

    When you ask a question, it is best to describe it in more detail, such as what project you want to implement.

    According to your previous question, I think you are implementing it in Asp.Net MVC.

    You can refer to the example below.

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        @using (Html.BeginForm("Index", "Home", FormMethod.Post))
        {
            <input type="text" id="txtName" name="name" />
            <input type="submit" id="btnSubmit" value="Get Current Time" />
        }
        @if (ViewBag.Message != null)
        {
            <script type="text/javascript">
                window.onload = function () {
                    alert("@ViewBag.Message");
                };
            </script>
        }
    </body>
    </html>
    
     // GET: Home
            public ActionResult Index()
            {
              
                return View();
            }
    
            [HttpPost]
            public ActionResult Index(string name)
            {
                ViewBag.Message = "success";
                return View();
            }
    

    1

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.