我有一个简单的脚本,可以使用Javascript在HTML字段中显示字符串的长度。我使用的长度函数不能正常工作。但我无法理清解决方案。请指教。
@foreach (var val in ViewData["Students"] as List<Students>)
{
var state = @val.state; // its working fine
if ( (@state.length == 7)) // its not working length function fails
{
<p> I am : @state : with length : @state.length</p>
}
}
答案 0 :(得分:1)
您使用Razor在C#中编程,这不是Javascript问题。
如果state
是收藏集,请尝试改为使用属性.Count
:
@foreach (var val in ViewData["Students"] as List<Students>)
{
var state = @val.state; // its working fine
if ( (@state.Count == 7)) // its not working length function fails
{
<p> I am : @state : with length : @state.Count</p>
}
}