对象引用时的错误未设置为对象的实例。 [英] Error at object reference not set to an instance of an object.
问题描述
objModel模型为null&
objModel Model is null &
public ClusterModel()
不是tri€
我尝试过:
查看页面:
@model COCSIntimation.Models.ISIProcessListModel
@ {Html.RenderPartial(_ Cluster,Model.objModel);在对象引用未设置为对象实例时获取错误。
型号:
公共类ISIProcessListModel
{
public ClusterDetails.ClusterModel objModel {get;组; }
}
控制器:
public ActionResult Index()
{
ISIProcessListModel objProcessModel = new ISIProcessListModel();
返回View(objProcessModel);
}
类库:
公共类ClusterModel
{
public ObservableCollection< SelectListItem>参数;
公共字符串MCLELDescription {get;组; } $ / $
public ClusterModel()
{
string companycode = HttpContext.Current.Session [iCompanyCode ] .ToString();
int icompanycode = Convert.ToInt32(companycode);
string CECodes =2,3,4, 5,6,7;
SharedDA.GeneralClass obj = new SharedDA.GeneralClass();
DataSet objds = new DataSet();
objds =(DataSet)obj.GetClusterElements(1,CECodes);
var empList = objds.Tables [0] .AsEnumerable()。选择(dataRow => new ClusterModel {MCLELDescription = dataRow。字段< string>(MCLEL_Description)})。ToList();
}
}
部分查看:
@model ClusterDetails.ClusterModel
@(Html.EIPMVCLabel(lblIndependentCompany,@ Model.MCLELDescription))
is not trigerring
What I have tried:
View Page:
@model COCSIntimation.Models.ISIProcessListModel
@{ Html.RenderPartial("_Cluster", Model.objModel); } Getting error at "Object reference not set to an instance of an object."
Model:
public class ISIProcessListModel
{
public ClusterDetails.ClusterModel objModel { get; set; }
}
Controller:
public ActionResult Index()
{
ISIProcessListModel objProcessModel = new ISIProcessListModel();
return View(objProcessModel);
}
Class Library:
public class ClusterModel
{
public ObservableCollection<SelectListItem> Parameters;
public string MCLELDescription { get; set; }
public ClusterModel()
{
string companycode = HttpContext.Current.Session["iCompanyCode"].ToString();
int icompanycode = Convert.ToInt32(companycode);
string CECodes = "2,3,4,5,6,7";
SharedDA.GeneralClass obj = new SharedDA.GeneralClass();
DataSet objds = new DataSet();
objds = (DataSet)obj.GetClusterElements(1, CECodes);
var empList = objds.Tables[0].AsEnumerable().Select(dataRow => new ClusterModel { MCLELDescription = dataRow.Field<string>("MCLEL_Description") }).ToList();
}
}
Partial View:
@model ClusterDetails.ClusterModel
@(Html.EIPMVCLabel("lblIndependentCompany", @Model.MCLELDescription))
推荐答案
尝试如下:
Try like below:
@{Html.RenderPartial("_Cluster", new ViewDataDictionary(Model.MCLELDescription))};
尝试如下:
Try like below:
@{Html.RenderPartial("", new ViewDataDictionary(Model.MCLELDescription))};
这篇关于对象引用时的错误未设置为对象的实例。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!