开发者

asp.net mvc create view

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜