c# - ASP.Net MVC forms/model binding and delete records? -
i have model i'm loading table within form. records retrieved oracle db using ef6 , loaded model. want user able select records delete database via checkbox in each row in form.
the function retrieve attendees:
public list<webinarattendeeslist> getattendees(string webinarkey) { string connectionstring = "password=password;user id=user;data source=oracle"; list<webinarattendeeslist> r = null; using (webinarattendeeslistdbcontext context = new webinarattendeeslistdbcontext(connectionstring)) { var result = w in context.webinarattendeeslist w.webinarkey == webinarkey orderby w.firstpollcount, w.secondpollcount select w; r = result.tolist(); } return r; }
here model:
[table("webinarattendeeslist")] public class webinarattendeeslist { [key, column("wal_id")] public int wa_id { get; set; } [column("wal_cli_rid")] public int participantid { get; set; } [column("wal_fullname")] public string fullname { get; set; } [column("wal_email")] public string email { get; set; } [column("wal_jointime")] public string jointime { get; set; } [column("wal_timeinsession")] public string timeinsession { get; set; } [column("wal_leavetime")] public string leavetime { get; set; } [column("wal_firstpollcount")] public int firstpollcount { get; set; } [column("wal_secondpollcount")] public int secondpollcount { get; set; } [column("wal_attendedwebinar")] public int attendedwebinar { get; set; } [column("wal_makeup")] public int makeup { get; set; } [column("wal_comments")] public string comments { get; set; } [column("wal_registrantkey")] public string registrantkey { get; set; } [column("wal_webinarkey")] public string webinarkey { get; set; } }
when form submitted, passing model function store records in ef6.
public actionresult postattendees(icollection<webinarattendeeslist> attendees) { foreach (webinarattendeeslist attendee in attendees) { updateattendee(attendee); } }
how edit model allow delete records selected , update ones don't have checkbox selected? if put int delete
property on model has no column attribute exception:
ora-00904: "extent1"."delete": invalid identifier
i found tutorial i'm not using helpers in creation of form , not have viewmodels , doesn't explain how handle doing different things different records based on checkbox: http://johnatten.com/2014/01/05/asp-net-mvc-display-an-html-table-with-checkboxes-to-select-row-items/
is there better way this?
yes. models properties in ef suppose column. should use notmapped
attribute if don't want property treated 'column' in database.
Comments
Post a Comment