I have created a Create view.Now the thing is that I want to throw all the fields from the create view into the data plus two other fields which are not on the view which are 开发者_StackOverflowcreated date and created by .How will I do that?
On this sample code from NerdDinner, look at the comments:
// POST: /Dinners/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Dinner dinner)
{
if (ModelState.IsValid) {
try {
// here you can add your other fields:
dinner.CreatedDate = DateTime.Now;
dinner.CreatedBy = LoggedUserId; // you have to figure out how to get this
dinnerRepository.Add(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new {id = dinner.DinnerID });
}
catch {
ModelState.AddRuleViolations(dinner.GetRuleViolations());
}
}
return View(dinner);
}
精彩评论