如何在视图中显示计算值? [英] How to display a calculated value in a view?
本文介绍了如何在视图中显示计算值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是ASP.NET和MVC架构的新手.我要在进行如下计算后在视图中显示数字
I'm new to ASP.NET and MVC architecture. I want to display a number in a view after doing a calculation as follows
如何在视图中显示 totalmessage
?
推荐答案
您可以使用视图模型来保存数据.
You can use a view model to hold your data.
public class TotalViewModel
{
public int Total {get; set;}
public string Message {get; set;}
}
然后在控制器中
public ActionResult Calculate()
{
// do your calculations...
var model = new TotalViewModel { Message = "Total = ", Total = total };
return this.View(model);
}
和视图
@model Path.To.Your.TotalViewModel
<p>@Model.Message @Model.Total</p>
这篇关于如何在视图中显示计算值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文