Asp.net mvc create view

I created Create view. Now the thing is, I want to cast all fields from the create view into data and two other fields that are not in the view, which are created by date and created. How am I going to do this?

+2


a source to share


1 answer


For this code example from NerdDinner, review 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


a source







All Articles