using System;
using System.ComponentModel.DataAnnotations;
namespace HelloWorldMvcApp
{
public class SampleViewModel
[Required]
[MinLength(10)]
[MaxLength(100)]
[Display(Name = "Ask Magic 8 Ball any question:")]
public string Question
get;
set;
}
//See here for list of answers
public string Answer
@model HelloWorldMvcApp.SampleViewModel
@{
Layout = null;
<!DOCTYPE html>
<!-- template from http://getbootstrap.com/getting-started -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Clicky</title>
<style>
a
color: #333;
outline: none;
padding-left: 3px;
padding-right: 3px;
text-decoration: underline;
a:link, a:visited, a:active, a:hover
a:hover
background-color: #c7d1d6;
a.quote
border: 1px inset #808080;
text-decoration: none;
a.quote:active, a.quote:hover
background-color: #FFFF66;
a.quote:link, a.quote:visited
background-color: #00CC66;
</style>
</head>
<body>
<div class="container">
@Html.ActionLink("Clicky", "Action", new { quoteContentID = 1 }, new { @class = "quote" })
</div>
</body>
</html>
using System.Web.Mvc;
using System.Collections.Generic;
public class HomeController : Controller
[HttpGet]
public ActionResult Index()
return View(new SampleViewModel());
[HttpPost]
public JsonResult GetAnswer(string question)
int index = _rnd.Next(_db.Count);
var answer = _db[index];
return Json(answer);
private static Random _rnd = new Random();
private static List<string> _db = new List<string>
"Yes", "No", "Definitely, yes", "I don't know", "Looks like, yes"
;