Welcome to the tutorial on HOW TO ADD TWO NUMBERS IN ASP.NET MVC C#.
You are at absolutely correct page to give a good start.
Now Lets start our job. At first Create a model in Models folder named addmodel.cs.
Add > class . addmodel.cs
// code:
public class addmodel
{
public int firstNum { get; set; } //for first number
public int secondNum { get; set; } //for second number
public int result { get; set; } //for storing result after addition
}
Now we are going to add a actionResult Method in Home Controller
Use a using
//code:
using YourProjectName.Models;
[HttpPost] //this is required for post type of submit
public ActionResult Index(addmodel am) //for this you have to add a using
{
am.result = am.firstNum + am.secondNum;
return View(am); //sending result to view so that we can see it :)
}
Now time to show output in a page.
Write this code in Views/Home/index.cshtml
@*Code: *@
@model YourProjectName.Models.addmodel
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<br />
@Html.EditorFor(m=>m.firstNum)
<br /><br />
@Html.EditorFor(m=>m.secondNum)
<br /><br />
@Html.DisplayFor(m=>m.result)
<br /><br />
<input type="submit" value="Add"/>
}
Now you are ready to go.Just Run The project. If you are still confused then watch this video. And Don't forget to subscribe for more similar kind of stuff. Good luck :)
You are at absolutely correct page to give a good start.
Now Lets start our job. At first Create a model in Models folder named addmodel.cs.
Add > class . addmodel.cs
// code:
public class addmodel
{
public int firstNum { get; set; } //for first number
public int secondNum { get; set; } //for second number
public int result { get; set; } //for storing result after addition
}
Now we are going to add a actionResult Method in Home Controller
Use a using
//code:
using YourProjectName.Models;
[HttpPost] //this is required for post type of submit
public ActionResult Index(addmodel am) //for this you have to add a using
{
am.result = am.firstNum + am.secondNum;
return View(am); //sending result to view so that we can see it :)
}
Now time to show output in a page.
Write this code in Views/Home/index.cshtml
@*Code: *@
@model YourProjectName.Models.addmodel
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<br />
@Html.EditorFor(m=>m.firstNum)
<br /><br />
@Html.EditorFor(m=>m.secondNum)
<br /><br />
@Html.DisplayFor(m=>m.result)
<br /><br />
<input type="submit" value="Add"/>
}
Now you are ready to go.Just Run The project. If you are still confused then watch this video. And Don't forget to subscribe for more similar kind of stuff. Good luck :)
No comments:
Post a Comment