Thursday, February 18, 2010

Anti-Sample of the day, bad sample variable, wasting time .....

This a sample from one of the MVC books I have been reading:

using System.Web.Mvc;
namespace ViewSamples.Controllers
public class ViewDataController : Controller
public ActionResult Index()
ViewData.Add("one", "onevalue");
ViewData.Add("two", "twovalue");
return View(3);

WTF the 3 stands for ? IS it somehow magically related to "three" or the collection size ?

Try matching signatures in msdn:

View(Object) Creates a ViewResult object using the model that renders a view to the response.

Then continue reading "the book":
Notice the values that are added in the controller in listing 4.6. We have three key/value
pairs and an object set to the Model property (by virtue of passing in “3” to the View

Virtue ? "3" ?

Passing some reasonable OBJECT as Model insted of magical autoboxing small int with coincidental value 3, would be bit easier to understand....

No comments:

Post a Comment