[英]Display local variable in MVC grid view
I want to calculate the age in view class without changing the model class . 我想在视图类中计算年龄而无需更改模型类。
I already calculate the age .But it doesn't show in the web grid So problem is how to display the variable in grid 我已经计算了年龄,但是它没有显示在网络网格中,所以问题是如何在网格中显示变量
<% var age=(DateTime.Today.Year - item.BirthDay.Value.Year);
@Html.DisplayTextFor(model => age);
%>
i didn't find correct answer .finally came up with solution 我没有找到正确的答案。最后想出了解决方案
<% var age=(DateTime.Today.Year - item.BirthDay.Value.Year);
%>
<%=age %>
(model => age)
is it right? 这样对吗? age is not a property of model.
年龄不是模型的属性。 you should try
你应该试试
@Html.TextBox("tbAge", age);
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.