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?
ViewBag.Title = "Index";
<!-- HTML form with "Post" method initiated. -->
<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;
modified 8-Oct-17 22:58pm.