asp.net mvc - Capturing and returning datetime when form is submitted in MVC application -
i have basic crud style mvc application has form submitted. when form submitted, i'd capture date , time , homecoming index view next other form info presented there. how capture date , time form submmitted (posted) , how pass info index view?
view
<table class="table table-striped"> <tr> <th> @html.displaynamefor(model => model.firstname) </th> <th> @html.displaynamefor(model => model.lastname) </th> <th> ****need have display date/time form submitted here **** </th>
controller
public class homecontroller : controller { private applicationdbcontext db = new applicationdbcontext(); public actionresult index() { homecoming view(); } // post: applications/create // protect overposting attacks, please enable specific properties want bind to, // more details see http://go.microsoft.com/fwlink/?linkid=317598. [httppost] [validateantiforgerytoken] public actionresult index([bind(include = "id,firstname,lastname")] application application) { if (modelstate.isvalid) { db.applications.add(application); db.savechanges(); homecoming redirecttoaction("index"); } homecoming view(application); }
model
public class application { public int id { get; set; } public bool married { get; set; } [displayname("unmarried")] public bool single { get; set; } [required] [displayname("first name")] public string firstname { get; set; } [displayname("middle initial")] public string middleinitial { get; set; } [required] [displayname("last name")] public string lastname { get; set; }
so 1 time user submits form need pass current date , time index view , display underneath lastly name field. how can this?
added field model:
public datetime getdate { get; set; }
in controller:
public actionresult create() { homecoming view(); } // post: customers/create [httppost] [validateantiforgerytoken] public actionresult create([bind(include = "id,firstname,lastname, getdate")] client customer) { if (modelstate.isvalid) { customer.getdate = datetime.now; db.customers.add(customer); db.savechanges(); homecoming redirecttoaction("index"); } homecoming view(customer); }
view
<td> @html.displayfor(modelitem => item.getdate) </td>
the date client submitted form displaying!
asp.net-mvc
No comments:
Post a Comment