Skip to content

Instantly share code, notes, and snippets.

@gprasant
gprasant / Results.cs
Created May 17, 2012 13:11
Write less code
//output :
Normal Array Elapsed Time: 10831
Parallel For Elapsed Time: 39028
Clone Elapsed Time: 2149
//code
[Test]
public void zz()
{
public dynamic ViewBag {
get{
if (_dynamicViewDataDictionary == null) {
_dynamicViewDataDictionary = new DynamicViewDataDictionary(() => ViewData);
}
return _dynamicViewDataDictionary;
}
}
protected internal virtual ViewResult View(string viewName, string masterName, object model) {
if (model != null) {
ViewData.Model = model;
}
return new ViewResult {
ViewName = viewName,
MasterName = masterName,
ViewData = ViewData,
TempData = TempData
library(Rook)
# to install Rook, which makes it possible to run R as a server,
# R -q -e "install.packages('Rook', repos='http://cran.r-project.org')"
app <- function(env){
req <- Rook::Request$new(env)
res <- Rook::Response$new()
res$write(42)
res$finish()
public class Student
{
public int PhysicsScore { get; set; }
public float MathScore { get; set; }
public char PhysicsGrade { get; set; }
public char MathGrade { get;set; }
public string Name { get;set; }
}
@Html.TextBoxFor(student => student.Name)
@Html.TextBoxFor(student => student.PhysicsScore)
@Html.TextBoxFor(student => student.MathScore)
@Html.TextBoxFor(student => student.PhysicsGrade)
@Html.TextBoxFor(student => student.MathGrade)
<input data-val="true" id="Name" name="Name" type="text" value="">
<input data-val="true" data-val-number="The field PhysicsScore must be a number." data-val-required="The PhysicsScore field is required." id="PhysicsScore" name="PhysicsScore" type="text" value="">
<input data-val="true" data-val-number="The field MathScore must be a number." data-val-required="The MathScore field is required." id="MathScore" name="MathScore" type="text" value="">
....
public class Student
{
// Notice the nullable types
public int? PhysicsScore { get; set; }
public float? MathScore { get; set; }
public char? PhysicsGrade { get; set; }
public char? MathGrade { get;set; }
public string Name { get;set; }
public ViewResult Save(Model modelToSave)
{
if(ModelState.isValid)
{
modelToSave.Save();
// redirects to the list action if the save is successful
return RedirectToAction("Index");
}
//if there are any errors, the same edit View is returned.
return View("Edit", modelToSave);
return RedirectToAction("Index", new {message="Saved successfully"});