Reputation: 1289
I'm new to ASP.NET and MVC architecture. I want to display a number in a view after doing a calculation as follows
How can I display the totalmessage
in a view?
Upvotes: 0
Views: 2955
Reputation: 1847
You can use a view model to hold your data.
public class TotalViewModel
{
public int Total {get; set;}
public string Message {get; set;}
}
Then in the controller
public ActionResult Calculate()
{
// do your calculations...
var model = new TotalViewModel { Message = "Total = ", Total = total };
return this.View(model);
}
And the view
@model Path.To.Your.TotalViewModel
<p>@Model.Message @Model.Total</p>
Upvotes: 3
Reputation:
You can use ViewBag for any data to pass view, add these code to the Calculate method you have;
ViewBag.total = totalMessage;
than in the Calculate.cshtml view;
<p>@ViewBag.total</p>
that's all
Upvotes: 0