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?
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?
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>
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