c# - Asp.Net - IEnumerable properties not binding to model -
i nullpointerexception
error when attempt render @model.columns
in view. i'm using linqtoexcel.
relevant code parts:
model:
namespace steer.models { public class upfile { // irrelevant properties (name,size,filetype) omitted public ienumerable<string> columns { get; set; } public ienumerable<linqtoexcel.row> rows { get; set; } public class upfiledbcontext : dbcontext { public dbset<upfile> upfiles { get; set; } } } }
view:
@model steer.models.upfile @foreach (var item in model.columns) { <th>@item</th> }
controller:
upfile = new upfile(); // name, size, filetype binding omitted // here attempt bind columns , rows uploaded excel file var excel = new excelqueryfactory(appdomain.currentdomain.basedirectory + "uploaded\\" + up.name); var firstsheet = excel.getworksheetnames().first(); // rows ienumerable up.rows = c in excel.worksheet(firstsheet) select c; // getcolumnnames returns list. up.columns property ienumerable. up.columns = excel.getcolumnnames(firstsheet); db.upfiles.add(up); db.savechanges();
name
, size
, filetype
set fine. columns
, rows
properties empty.
the extraction of excel file works fine, can directly send excel rows view. when try reference properties have troubles.
// get: files/details/5 public actionresult details(int? id) { if (id == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } upfile upfile = db.upfiles.find(id); if (upfile == null) { return httpnotfound(); } return view(upfile); }
also!! when insert breakpoint @ db.savechanges()
, data there
Comments
Post a Comment