MVC 3 Returning Last Record Submitted for Edit
I have an MVC 3 application that I have put together which contains two roles. Admin and User are both my roles. I have a list of movies that are displayed on the开发者_开发技巧 Index.cshtml page in my View folder. I am trying to figure out how to display the last record submitted to the end user who just put it in. Just in case they may have "fat fingered" something.
My Index Code:
<td>
return last record to user to edit incase they typed something wrong.
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
@if (User.IsInRole("Administrator"))
{
@Html.ActionLink("Delete |", "Delete", new { id = item.ID })
}
</td>
The Controller Side:
public ActionResult Edit(int id)
{
Person person = db.Person.Find(id);
return View(person);
}
Any help would be greatly appreciated.
So you want to get the last movie that was submitted by currently logged user? I assume you have an association between the movie and the user:
var movie = db.Movies.Where(m => m.UserId == currentUserId).OrderByDescending(m => m.Id).FirstOrDefault()
精彩评论