Reputation: 1
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
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