Reputation: 13
I did a currency converter. but i have a problem. when i click the calculate the page refreshing and the datas which entered by user is cleaning. i think it is because of using return View();
:) .How can i solve this problem? Thanks
{
ViewBag.Result = frmAmount;
}
return View();
View
</p>
<p>
<label for="text3">Amount:</label>
<input type="text" name="frmAmount" />
</p>
<p>
<input type="submit" value="Calculate" />
</p>
<p>
<label for="text3">Sonuç:@ViewBag.Result</label>
</p>
For Example the amount be wiped when button clicked
Upvotes: 0
Views: 1328
Reputation: 3073
The amount data is cleaning because when you click on calculate button you are returning the same view again. In order to keep amount data you should also pass amount value to the view by ViewBag (ViewBag.Amount
) or by passing object model into view by using second parameter of View(viewName, model)
.
In general, I would recommend you to try avoid using ViewBag variables. The preffered method is to use ViewModel instead due to e.g. refactoring. You can read more about it here: click!
Upvotes: 2