/*
using System;
using System.Collection.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace GuessingGame.Controllers
{
public class GameController : Controller
public ActionResult Index()
Session["Answer"] = new Random().Next(1, 10); //f9
return View();
}
[HttpPost]
public ActionResult Index(GameViewModel model)
ViewBag.Win = model.Guess == (int)Session["Answer"];
return View(model); //(f9 for breakpoint)
namespace GuessingGame.Models
public class GameViewModel
public string PlayerName ( get; set; }
public int Guess { get; set;}
override string ToString()
return String.Format("{0} ({1})", PlayerName, Guess);
@model GuessingGame.Models.GameViewModel
@{
ViewBag.Title = "Guessing Game";
<h2> @ViewBag.Title </h2>
@if (!(ViewBag.Win ?? false)) //f9
if (ViewBag.Win != null && !ViewBag.Win)
<h2>Sorry, @Model.PlayerName, @Model.Guess is incorrect :(</h2>
using (Html.BeginForm())
@Html.AntiForgeryToken()
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(
m => m.PlayerName,
htmlAttributes: new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.EditorFor(
new { htmlAttributes = new { @class = "form-control" } })
</div>
m => m.Guess,
<div class="col-md-offset-2 col-md-10>
<input type="submit" value="Guess" class="btn btn-default"/>
else
<h2>That's it, @Model.PlayerName! The answer was @Model.Guess!</h2>
<div>
@Html.ActionLink("Start Over", "Index")
//add new item: class "GameViewModel.cs"
// right click add view: Name: index, Template: Empty, Model Class:
//add new controller: first one
// cntrl + , type bootstrap.css
// cntrl + .
//debug, windows, watch, 1.
//f10: step over
//f5: continue running
//cntrl d+q
// cntrl shift f9: removes all breaks
*/