La manera más simple limpia proporciona una clase de modelo, un controlador y una vista. Por favor, mira el siguiente ejemplo:
El Modelo:
public class CalculatorModel {
public int Result { get; set; }
public int FirstOperand { get; set; }
public int SecondOperand { get; set; }
}
El controlador:
public class CalculatorController : Controller {
[HttpGet]
public ActionResult Sum() {
CalculatorModel model = new CalculatorModel();
//Return the result
return View(model);
}
[HttpPost]
public ActionResult Sum(CalculatorModel model) {
model.Result = model.FirstOperand + model.SecondOperand;
//Return the result
return View(model);
}
}
La Vista:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CalculatorModel>" %>
<% using (Html.BeginForm("Sum", "Calculator", FormMethod.Post, new { id = "calcForm" })) { %>
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr valign="top">
<td>
<%= Html.LabelFor(model => model.FirstOperand) %>
<%= Html.TextBoxFor(model => model.FirstOperand) %>
</td>
</tr>
<tr valign="top">
<td>
<%= Html.LabelFor(model => model.SecondOperand) %>
<%= Html.TextBoxFor(model => model.SecondOperand) %>
</td>
</tr>
</table>
<div style="text-align:right;">
<input type="submit" id="btnSum" value="Sum values" />
</div>
<% } %>
Mi consejo es seguir algún tutorial sobre ASP .NET MVC. Puedes encontrar muchos con google. El ASP.NET MVC web site es un buen lugar para comenzar.
Espero que ayude!
¿Tiene la intención de hacerlo a través de Ajax? – ahsteele
no. solo envíe los datos, calcule y devuelva el valor – Jason94