user1448245
user1448245

Reputation: 1

MVC3 - Input and Output value

I just learned MVC3 from an example but I haven't found what I'm looking for. Something like in ASP.NET WebForms:

public void Something()
{
    string a = TextBoxA.Text;
    string b = TextBoxB.Text;
    TextBoxC.Text = a + b;
}

How to do that in MVC ? I tried to create an ActionResult but I don't want to redirect to another View.

Upvotes: 0

Views: 220

Answers (1)

Pravin Pawar
Pravin Pawar

Reputation: 2569

You might want to do this @ client side i.e. using jQuery etc. In MVC, it has to be managed at controller side updating required properties of viewModel. That viewmodel intern is binded with controls on actual view

//Model
public class AddViewModel
{
    public int One { get; set; }
    public int Two { get; set; }
    public int Result { get; set; }
}
//Controller
public ActionResult Index()
{
    AddViewModel obj = new AddViewModel();
    obj.One = 1;
    obj.Two = 2;
    obj.Result = obj.One + obj.Two;
    return View(obj);
}
//View
@model MvcApplication3.Models.AddViewModel
@Html.EditorFor(model => model.One)
@Html.EditorFor(model => model.Two)
@Html.EditorFor(model => model.Result)
<input type="submit" value="Save" />

Upvotes: 2

Related Questions