I am working on ASP.net MVC . Here, M Stands for just "Model" . A Model that can be mapped to database.
Usually, i Strongly bind my View with Model .
But, recently i was hearing about View Model that is some thing different than just Model.
Is ViewModel Part of MVC
or MVVM
( ModelViewViewModel) ?
What is the basic difference between ViewModel and Model. I would like to give a small example as 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 });
}
That's it . I am not able to understand where this ViewModel
comes into Picture
please clarify me on following:
1.The basic difference between ViewModel and Model
2.Is View Model Part of MVC or MVVM Architecture?
How to implement above example incase of using ViewModels?
If View Models are Part of MVC, then where will they be in the folder structure of the Application?