Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to calculate two text box value without using any scripting components

What I have tried:

how to calculate values in serverside mvc
Posted
Updated 26-Dec-17 2:47am
Comments
Nakhia_ind 26-Dec-17 5:35am    
take two textbox with name attributes
in mvc action method take formcollection object as a argument like formcollection frm
then through formcollection object collect the textbox value like
string n1 = frm["text1"].ToString();

1 solution

one of the method.
public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult PostActionMethod()
        {
            string a = Request["txtA"];
            string b = Request["txtb"];
            int a1, b1;
            int.TryParse(a, out a1);
            int.TryParse(b, out b1);
            int c = a1 + b1;
            ViewBag.Value = c;
            return View("Index",c);
        } 
    }


HTML
@using (Html.BeginForm("PostActionMethod", "Home", FormMethod.Post))
{ 
    @Html.TextBox("txtA");
    @Html.TextBox("txtB");     
    <input type="submit" value="Sum" /> 
}
Result: <h1>@ViewBag.Value</h1>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900