Note that there are some explanatory texts on larger screens.

plurals
  1. POCommon Data Properties In ASP.NET MVC 2 Data Objects
    primarykey
    data
    text
    <p>Okay, I've been struggling with this for a while now.</p> <p>I have a standard MVC2 project and use EF4 to access data objects. Many of my data objects (and therefore database tables) have two common fields: UpdateUserAccountID and UpdateDate.</p> <p>In each of my controllers, I am currently setting this fields manually within each controller on the Edit action:</p> <pre><code> // POST: /Modes/Edit/2 [HttpPost] public ActionResult Edit(int id, FormCollection formValues) { Mode mode = _repository.GetMode(id); //Set update flags mode.UpdateUserAccountID = _userRepository.GetUserID(User.Identity.Name); mode.UpdateDate = DateTime.Now; try { UpdateModel(mode); _repository.Save(); return RedirectToAction("Details", new { id = mode.ModeID }); } catch { return View(mode); } } </code></pre> <p>Problem is, I want to update these two fields in a central place, regardless of the type of the controller. I am using Repository/IRepository pattern for my data objects. I also have set up a BaseController as I thought I could pass in my 'mode' object in the example above to a generic function in a base controller to set these two fields. But, I couldn't figure that out and the generic function has no awareness of these specific fields.</p> <p>Should I be creating a base class for my repositories instead? I can't envisage how that would work within the MVC framework. In webforms, I would just have had an interface that all my models implement with the common fields but i can't seem to fit it in to an MVC approach.</p> <p>Any help as to the approach to take would be great.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload