?
Solved

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

Posted on 2013-06-04
5
Medium Priority
?
1,543 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 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