假设我有以下模型和Index
操作方法。
public class detailsbyclientIdviewModel
{
public int upldId { get; set; }
public IPagedList<detailsbyClientId> detailsbyclientId { get; set; }
public IEnumerable<Metadata> metadata { get; set; }
public IEnumerable<int> Ids { get; set; }
public IEnumerable<Records> records { get; set; }
}
我有一个动作方法如下。
public ActionResult Index(detailsbyclientIdviewModel model)
{
documentVerificationBAL objBAL = new documentVerificationBAL();
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
List<Records> documentstobeVerified = objBAL.getverificationRecords();
//Assigning recieved data to Model
model = new detailsbyclientIdviewModel()
{
records = documentstobeVerified,
detailsbyclientId=new IPagedList<detailsbyclientId>()
};
return View(model);
}
我有很多动作方法并在视图中检索数据。在我的视图中,我有详细信息来自clientId.someproperties。当第一次运行页面时,我收到错误,例如对象未初始化(最终保持null
值)。那么如何初始化所有这些属性呢?
答案 0 :(得分:0)
我不认为你必须在Action中使用model作为输入才能将它作为输入返回给View。尝试:
public ActionResult Index()
{
documentVerificationBAL objBAL = new documentVerificationBAL();
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
List<Records> documentstobeVerified = objBAL.getverificationRecords();
//Assigning recieved data to Model
detailsbyclientIdviewModel model = new detailsbyclientIdviewModel()
{
records = documentstobeVerified,
detailsbyclientId=new IPagedList<detailsbyclientId>()
};
return View(model);
}