Have a form result invisible until submission?

I have a simple web application where the user inputs three integers into a form and receives the sum as a result.

My question is this: I'd like to have the actual sum value not appear until the user has Submitted. Meaning, when the page is opened up, the ViewBag just displays nothing. And then after submission, the ViewBag content appears. Is it possible for me to do this with the current code I have?

I'm aware this will probably require a JavaScript function. I just don't have very much experience integrating JS with C#.


ViewBag.Title = "Index";


<form action="" method="post">

Enter the 1st Number: <input id="firstInt" name="firstInt" type="text" value="0" /><br />
Enter the 2nd Number: <input id="secondInt" name="secondInt" type="text" value="0" /><br />
Enter the 3rd Number: <input id="thirdInt" name="thirdInt" type="text" value="0" /><br />

<input id="Submit" type="submit" value="submit" />
<input id="Reset" type="reset" value="reset" /><br /><br />
Sum = @ViewBag.result


public class HomeController : Controller
    public ActionResult Index(int firstInt = 0, int secondInt = 0, int thirdInt = 0)
        int sum = firstInt + secondInt + thirdInt;
        ViewBag.result = sum;
        return View();

0 Comment



Captcha image