首页 新闻 会员 周边

在方法中调用接口时出错

0
悬赏园豆:10 [已解决问题] 解决于 2018-04-11 08:22

[Dependency]
public static IFlow_FormAttrBLL A_BLL { get; set; }
/// <summary>
/// 反射遍历对象属性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="model"></param>
/// <returns></returns>
public static List<Flow_HelpModel> ForeachClassProperties<T>(T model)
{
int i = 0;
Type t = model.GetType();
List<Flow_HelpModel> list = new List<Flow_HelpModel>();
Flow_HelpModel helpmodel = new Flow_HelpModel();
PropertyInfo[] propertyList = t.GetProperties();
foreach(PropertyInfo item in propertyList)
{
i++;
if (i > 8)
{
if (item.Name != null)
{
object value = item.GetValue(model, null);
Flow_FormAttrModel entity = A_BLL.GetById(value.ToString());
helpmodel.currentChar = "tr" + item.Name;
helpmodel.currentTitle = entity.Name;
helpmodel.currentValue = value.ToString();
helpmodel.Example = getExample(entity.AttrType);
list.Add(helpmodel);
}
}
}
return list;
}

 

这是后端调用

<table id="AttrList" class="fromEditTable setTextWidth3">
@foreach(var obj in ForeachClass.ForeachClassProperties(Model))
{

<tr id="@obj.currentChar">
<td style="text-align:right">
@obj.currentTitle
</td>
<td>
@obj.Example<input id="@obj.currentChar.Substring(2,obj.currentChar.Length)" name="@obj.currentChar.Substring(2,obj.currentChar.Length)" type="hidden" value="@obj.currentValue"/>
</td>
<td><a href="javascript:deleteCurrentTR('@obj.currentChar')">[删除]</a></td>
</tr>
}
</table>

 

前台我是用了一个foreach循环

但是一到调用A_BLL.GetById()方法时就会出现错误未将对象引用到实例

Zero77的主页 Zero77 | 菜鸟二级 | 园豆:211
提问于:2018-03-20 17:02

把代码放到代码块里,这样可读性太差,不想去阅读。

Shendu.cc 6年前

@Shendu.cc: 我现在还是处于学习状态。不太懂这些。。呵呵

Zero77 6年前
< >
分享
最佳答案
0

object value = item.GetValue(model, null);  value变量为null

收获园豆:10
ndgail | 初学一级 |园豆:148 | 2018-03-20 17:47

value这个是有值的。。我看过

Zero77 | 园豆:211 (菜鸟二级) | 2018-03-20 18:05

@Zero77: 你定义静态的A_BLL?有给赋值吗?

ndgail | 园豆:148 (初学一级) | 2018-03-20 18:08

@ndgail: 这个A_BLL接口不应该直接用[Dependency]指定就可以吗?我再控制器里面这样直接用是可以的.

这个是我在一篇文档中看见的Unity注入应用。由于我对这个也不太了解。然后我就这么一直用着。不知道到这就为什么出错了

Zero77 | 园豆:211 (菜鸟二级) | 2018-03-20 18:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册