asp.net mvc - MVC error path cannot be null -
i have 2 questions: 1) list of record database , displaying on index page table. error: additional information: argument 'path' cannot null, empty or contain white space.
controller:
public actionresult index() { records m = new records(); var records = db.records .include((m.types).tostring()); return view(records .tolist()); }
in modal:
public partial class records { public int id { get; set; } public nullable<int> types{ get; set; } public nullable<system.datetime> date { get; set; } }
2) have created models database using .edmx file, apply validation above fields. can [required]public nullable<int> types{ get; set; }
etc... future if decide change database , perform update .edmx file [require] labels gone. how solve problem'
route config file
public class routeconfig { public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); } }
part one: working out details in comments above
as far validation, it's idea establish separate models used through mvc , not pass database models. lot of times may one-to-one, it's not (keep secure information out of wrong hands). said, there libraries automapper make easy (thankfully). example, given model:
public partial class records { public int id { get; set; } public nullable<int> types{ get; set; } public nullable<system.datetime> date { get; set; } }
you can create view model:
public class recordsviewmodel { [required, hiddeninput] public int id { get; set; } [required, range(1,100)] public nullable<int> types{ get; set; } [required, datatype(datatypes.datetime)] public nullable<system.datetime> date { get; set; } }
then map them using like:
records m = new records(); var records = db.records .include((m.types).tostring()); ilist<recordsviewmodel> = mapper.map<ilist<recordsviewmodel>>(records); return view(recordsviewmodel);
Comments
Post a Comment