Wednesday, June 30, 2010

Should an object be created in an Unhealthy State? Passing from Create controller to View

Programmer Question

Hi



What are the advantages of passing a blank object eg Client from the controller?



public ActionResult Create()
{
Client client = new Client();
return View(client);
}

//
// POST: /Client/Create
[HttpPost]
public ActionResult Create(Client clientToAdd)
{
try
{
clientRepository.Insert(clientToAdd);
return RedirectToAction("Index");


As opposed to:



 public ActionResult Create()
{
return View();
}

//
// POST: /Client/Create
[HttpPost]
public ActionResult Create(Client clientToAdd)
{
try
{
clientRepository.Insert(clientToAdd);
return RedirectToAction("Index");


The reason being is that: Should an object (eg the Client) be created in an 'unhealthy' state ie blank?



Cheers



Dave



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails