your view model should look like this
public class AddViewModel
{
public int a { get; set; }
public int b { get; set; }
public int Total { get; set; }
}
and in the cshtml
<td class="tdCol2Align">
@Html.TextBoxFor(m=> m.a)
</td>
<td class="tdCol2Align">
@Html.TextBoxFor(m=> m.b)
</td>
in the controller
[HttpPost]
public JsonResult Add(AddViewModel model)
{
int iSum = model.a + model.b;
model.Total = iSum;
return Json(model);
}
Edit
View model is there to render your views don't place any logic inside that. if you have more complex model then it will be hard to map Model
with ViewModel
. for this you can use AutoMapper or ValueInjector for mapping between model and view model.
link for automapper http://automapper.codeplex.com/
link for value injector http://valueinjecter.codeplex.com/
hope this helps