SIGN UP MEMBER LOGIN:    
ARTICLE

Arithmetic operation in ASP.NET MVC

Posted by Manish Singh Articles | ASP.NET MVC with C# November 30, 2011
This is a simple ASP.NET MVC application that performs arithmetic operations. ASP.NET MVC is the advanced version of ASP.NET. MVC is the three separated part that name is the models,views,controllers.
Reader Level:

Introduction : This is a simple ASP.NET MVC application that performs arithmetic operations. ASP.NET MVC is the advanced version of ASP.NET. MVC is the three separated part that name is the models,views,controllers. Every part performs different work in an ASP.NET  MVC application. Models is perform the business logic, Views is provide  the graphical user interface and last controller handle all views and models request. In this example we simple perform the arithmetic operation addition, subtraction, multiplication and division. In this program first we create the business logic add a class in model folder and second is pass the request in controller folder after that create a view. This is the simple application for beginners that help how to perform the arithmetic operation using  ASP.NET MVC tools.

Step1: Open the MVC ASP.NET application.

  • Open Visual Studio 2010.
  • Click file ->New->Projects.
  • Add a MVC ASP. NET 2 Empty Web application.

start111.gif

Step2: Add business logic in Models folder.

  • Right Click the models folder and add a class.
  • Right Click->add ->add new items->add class.
  • The Class name is "manish".

openmodelclass.gif

start111.gif

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace math123.Models
{
    public class Manish
    {
        public int sum(int a, int b)
        {
            int c = a + b;
            return c;
        } 
        public
int sub(int a, int b)
        {
            int c = a + b;
            return c;
        }
        public int mul(int a, int b)
        {
            int c = a * b;
            return c;
        }
        public int div(int a, int b)
        {
            int c = a / b;
            return c;
        }
    }
}

Step 3: Add a controller.

  • Right Click the controllers folder and add a controller.
  • Right Click->add ->add controller.
  • Controller name is "manu"
  • Add namespace in controller that name is "using math123.Models".

addcontroller.gif

copntrolleer.gif

Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using math123.Models;
namespace math123.Controllers
{
    public class manuController : Controller
    {
        //
        // GET: /manu/
        public ActionResult Index()
        {
            Manish man = new Manish();
            man.sum(10,20);
            man.sub(30, 10);
            man.mul(10, 50);
            man.div(100, 5);
            return View(man);
        }
    }
}

Step 4: Add a view.

  • Right Click on "ActionResult" and add view.
  • The view is the strong type.
  • The view name is the default name "index".

view.gif

viewdesign.gif

Code:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<math123.Models.Manish>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox2.Text = Model.sum(10, 20).ToString();
        TextBox3.Text = Model.sub(30, 10).ToString();
        TextBox4.Text = Model.mul(10, 50).ToString();
        TextBox5.Text = Model.div(100, 5).ToString();
    }
</script>
<
html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title
>
</head>
<
body bgcolor="#008040">
    <form id="form1" runat="server">
    <div style="background-color: #66CCFF">
    Sum of Number
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        Sub of Number
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />
        Mul of Number
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <br />
        Div of Number
        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        <br />
    </div>
    </form
>
</body>
</
html>

Step 5: Press crtl + f5 and show the result.

Output:

output.gif

Login to add your contents and source code to this article
share this article :
post comment
 

Hello dear My name is madina.i am interested in having a relationship with you and being your friend.i'm romantic and young Girl,you can send an email to my email address (karim_madina@ymail.com) so that I can send you more details about my self Including my picture.

Posted by madina karim Jan 04, 2012
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Gauge for SharePoint
Become a Sponsor