try this
public class HomeController : Controller
{
private static Random rand = new Random();
private string _randomnumber;
public ActionResult Index()
{
return View();
}
public int Random()
{
for (int i = 0; i < 2; i++)
{
_randomnumber= (Convert.ToString(rand.Next(1000, 9900)));
return new JsonResult { Data = _randomnumber, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
return _randomnumber;
}
<input type ="button" onclick=" GetMessage() " value=" Get Message"/>
<p></p>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function GetMessage() {
$.get("/{HomeControlle}r/{Random}", function(data) {
$("p").html(data);
});
}
</script>