首先,请原谅我的无知,我是C#和MVC格式的新手。
我正在尝试将模型中项目的结果值传递给自定义函数。我想传递一个字符串,这样我就可以操纵它,然后将字符串传递回View,以便更新我的CSS代码。基本形式是:
@foreach (var item in Model)
{
string tabval = "";
string status = "";
//This is where I am getting confused, how do I pass the value of
modelItem => item.status to my function StatusType()?
tabval = StatusType(status);
<td class="@tabval.ToString()">
@Html.DisplayFor(modelItem => item.status)
</td>
}
感谢您提供的任何帮助或指导。如果有更好的方法来处理此类操作,我也很高兴听到这些建议。
只需更换
tabval = StatusType(status);
与
tabval = StatusType(item.status);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句