开发者

asp.net mvc create view

开发者 https://www.devze.com 2022-12-28 09:16 出处:网络
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 开发者_StackOverflowcreat

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

精彩评论

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