Solved

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

Posted on 2013-06-04
5
1,451 Views
Last Modified: 2013-06-20
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
0
Comment
Question by:finance_teacher
  • 3
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 39220162
This is probably a good case of where you should use a viewmodel.  The viewmodel class will have the needed fields, but not the createdby, lastmodified, etc.  Thus you will avoid sending them to the client at all.

While you could use the domain class as the model and just omit the "invisible" fields from the view, you would be vulnerable to binding attacks, where anyone could inject whatever value they wanted into the supposedly invisible fields.

While you might not want to hand edit fields, views, etc. you are going to find out that it is generally a necessity.  The scaffolding is rudimentary at best, unless you plan to write your own scaffolding code.
0
 

Author Comment

by:finance_teacher
ID: 39220777
Can you provide some URL examples of the createdby, lastmodified, etc ?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 39221097
I'm not really clear on what you need.
0
 

Author Comment

by:finance_teacher
ID: 39221881
Just some website examples showing a examples of the createdby, lastmodified, etc in ViewModel/etc like you talked about.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 39222006
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now