A. Create a project of the basic type.
B. Create in the models directory:
DivModel.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.componentmodel.dataannotations;namespace mvcajaxdivtest.models{public class Divmodel { [ Required (errormessage = "Please enter an integer.")] public int dividend {set; get;} [Required (errormessage = "Please enter an integer.")] public int Divisor {set; get;} public int? Answer {set; get;} public int? remainder {set; get;}}}
C. Create HomeController.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Mvcajaxdivtest.models;namespace mvcajaxdivtest.controllers{public class Homecontroller:controller { //GET:/home/public actionresult Index () { return View (); } Public ActionResult Div (divmodel m) { if (m.divisor = = 0) { return Json (new {Divisortip = "divisor cannot be 0", an Swer = "", remainder = ""}, Jsonrequestbehavior.allowget); } Return Json (New {divisortip= "", Answer = m.dividend/m.divisor, remainder = m.dividend% m.divisor}, Jsonrequestbehavi Or. Allowget);}}}
D. Create the appropriate home/index.cshtml:
@model mvcajaxdivtest.models.divmodel@{viewbag.title = "Ajax Div Test";} E. Demonstration of effectiveness:
The AspNet MVC4 teaching -28:asp.net MVC4 Ajax Technology realizes the division to take the whole remainder fast demo