Create a calculator using ASP.NET MVC

0

I'm doing a small exercise of operations consuming a Web Service, but I can not find a way to show the result in the view, I'm not using Model.

Controller

 public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(int primero, int segundo)
    {
        // Creación de un objeto de referencia del servicio web  
        ServiceReference1.CalculatorSoapClient multi = new ServiceReference1.CalculatorSoapClient();

        // llama y almacena el resultado del servicio web en la variable  
        var multiplicac = multi.Multiply(primero, segundo);
        return View();
    }

View

 @Html.Label("PRIMER NUMERO");
@Html.Editor("primero")
@Html.Label("SEGUNDO NUMERO");
@Html.Editor("segundo")
@Html.Label("la respuesta es : " );
<input type="submit" name="Calcular" value="Calcualar" />

When I do the operation in the controller if it shows me the result, correctly. How can I do in the view to show me the result, or is there another way to do an operation?

    
asked by Daniel 09.01.2018 в 18:11
source

1 answer

1

you can pass the value to the view in the following way:

public ActionResult NombreView()
{
  ViewData["multiplicac"] = multi.Multiply(primero, segundo);
        return View();
}

and then in the view you can use it doing:

@Html.Encode(ViewData["multiplicac"].ToString()) 
    
answered by 09.01.2018 в 19:19