Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

ASP.Net MVC 4 C# -- scaffolding template, last modified date ?

How can I change below #8 to automatically populate the POdetail database columns (attached) ?

I don't want to hand code CreatedBy, LastModifiedBy, CreateDate, ModifiedDate each time I add a new table via the below like http://stackoverflow.com/questions/10935803/successful-model-editing-without-a-bunch-of-hidden-fields talks about.
----------------------------------------------------------------------------------
Steps
 1. create new APP
 2. RMB on Models FOLDER, Add, ADO.NET Entity Data Model
      ** Server = DBTEST
      ** Database = MVC_test (make sure table has "PK=ID" so Edit, Details, Delete work
 3. REBUILD
 4. RMB on Controllers FOLDER, Add, Controller, Default1Controller
      ** Template = MVC with read/write actions and views, using Entity Framework
      ** Model Class = Table6 (MvcApplication14.Models)
      ** Data Context Class = MVC_testEntities (MvcApplication14.Models)
 5. edit /Views/Shared/_Layout.cshtml --> <li>@Html.ActionLink("Test Text", "Index", "Default1")</li>
 6. change /Filters/InitializeSimpleMembershipAttribute.cs & Web.config to use ASP.net MVC 4 "SimpleMembership"
 7. run APP, login, click "Test Text", click "Create New", save
 8. WORKS, but displays CreatedBy, LastModifiedBy, CreateDate, ModifiedDate as editable textboxes and does not enter default values
      ** CreatedBy, LastModifiedBy, CreateDate, ModifiedDate need to automatically populate as HIDDEN fields
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of finance_teacher
finance_teacher

ASKER

Can you provide some URL examples of the createdby, lastmodified, etc ?
I'm not really clear on what you need.
Just some website examples showing a examples of the createdby, lastmodified, etc in ViewModel/etc like you talked about.
The point is that createdby, lastmodified, is not in the viewmodel, but in the Entity Framework model.  Any example of viewmodel will illustrate this concept.  This was covered in:

http://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models/

The scaffolding then will not include those fields for the view.  You still have to write code to handle the fields when you do the database work, but that's not really avoidable.