Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-04
5
Medium Priority
?
1,568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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