The AspNet MVC4 teaching -28:asp.net MVC4 Ajax Technology realizes the division to take the whole remainder fast demo

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.