I am working on ASP.net MVC. Here M supports only the "Model" . A model that can be mapped to a database.
I usually bind my View strongly to the model.
But lately I've heard about the View Model, something different from the model.
Is the ViewModel part of MVC or MVVM (ModelViewViewModel)?
What is the main difference between ViewModel and Model. I would like to give a small example of how I work in MVC:
My view:
<% using (Ajax.BeginForm("TestAjax", "Reviewer", new AjaxOptions { OnSuccess = "Callback", OnFailure = "Failed" })) { %> <table align="center"> <tr> <td class="tdCol1Align"> <label> Number1</label> </td> <td class="tdCol2Align"> <%=Html.TextBoxFor(Model => Model.number1)%> </td> </tr> <tr> <td class="tdCol1Align"> <label> Number2</label> </td> <td class="tdCol2Align"> <%=Html.TextBoxFor(Model => Model.number2)%> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Add" class="button" /> </td> </tr> </table> <% } %>
My model:
public class AddModel { public int number1 { get; set; } public int number2 { get; set; } }
and finally My controller :
[HttpPost] public JsonResult TestAjax(AddModel model) { int iSum = model.number1 + model.number2; return Json(new { Sum = iSum }); }
What is it. I can’t understand where this ViewModel goes into Image
Please clarify the following:
1. The main difference between ViewModel and Model
2.Is View Model Part MVC or MVVM Architecture?
How to implement the above example using ViewModels?
If view models are part of MVC, then where will they be in the folder structure of the application?
c # asp.net-mvc viewmodel model
Sai Avinash Oct 25 '13 at 11:27 2013-10-25 11:27
source share