.NET Fiddle

CSharp · Mvc

Model

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 { get; set; }
	}
}

View

@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>Bootstrap 101 Template</title>

		<!-- CSS Includes -->
		<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
		
		<style type="text/css">
			 #divPreloader {
            display: none;
        }
			.field-validation-error {
				color: #ff0000;
			}

		        #loadingcontent {
            position: fixed;
            color: white;
            opacity: 0.6;
            filter: alpha(opacity=60);
            width: 100%;
            height: 100%;
            background: #000;
            position: fixed;
            left: 0;
            top: 0;
            z-index: 2000;
        }

        #loadingcontentGif {
            position: fixed;
            top: 30%;
            left: 55%;
            height: 6em;
            padding-top: 2.3em;
            width: 50em;
            margin-left: -10em;
            padding-left: 2.1em;
            z-index: 3000;
        }
		</style>
	</head>
	
	<body>
		<div class="container">
			  <div id="divPreloader">
        <div id="loadingcontent">
        </div>
        <div id="loadingcontentGif">
            <img src="http://www.deadmau5.com/wp-content/themes/deadmau5/images/ajax-loader.gif" alt="Aguarde" /><br />
        </div>
    </div>
			<div class="col-md-6 col-md-offset-3">
	
					<button type="button" 
			class="btn btn-success submit downloadAnexo">Download</button>

				<br/><br/>
				<div class="alert alert-warning fade">
					<img src="http://entechprod.blob.core.windows.net/dotnetfiddle/morpheus.jpg" style="max-width:100%;"/><br/><br/>
					<strong><span class="alert-content"></span></strong>
				</div>
			</div>
		</div>

		<!-- JS includes -->
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
		<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	
		<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
		<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>
		
	    <script>
        $(".downloadAnexo").click(function () {
            $("#divPreloader").fadeIn();
            $.ajax({
                url: '@Url.Action("Index")',
                type: 'GET',
                success: function () {
                    $("#divPreloader").delay(1000).fadeOut();
                }
            });
        });
    </script>
	</body>
</html>

Controller

using System;
using System.Web.Mvc;
using System.Collections.Generic;

namespace HelloWorldMvcApp
{
	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"} ;
	}
}
;