What is ViewModel in ASP.Net MVC? Please Explain with example. [Resolved]

Posted by Kumarkrishna184 under ASP.NET MVC on 1/8/2016 | Points: 10 | Views : 3022 | Status : [Member] | Replies : 5
What is ViewModel in ASP.Net MVC? Please Explain with example.

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Sheonarayan on: 1/9/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
As quoted on TechFunda.com ViewModel is "a model class that can hold only those properties that is required for a view. It can also contains properties from more than one entities (tables) of the database. As the name suggests, this model is created specific to the View requirements. "

Read more about it at http://techfunda.com/howto/asp-net-mvc/viewmodel

As the name suggest this model is explicitly created to cater the need of the view so the name is ViewModel. For example, we may need to show records from more than one entities (database tables) on a single view. In this case we crate a ViewModel and use it as @model for the asp.net mvc view.

Above url has an example also.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 1/9/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Kumarkrishna184 Sir,
Recently we provided answer to a similar kind of question in DNF forum ( http://www.dotnetfunda.com/forums/show/20853/how-do-i-display-data-from-a-view-in-the-database ).

In short , A view model represents only the data that needs to be display on the view.

Hope the answer presented here (in the current thread and the link provided for the other thread) will be helpful.

In case you have any doubt, please let us know.

Thanks

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 1/10/2016 [Member] Starter | Points: 25

Up
0
Down
Thanks...

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 1/11/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Kumarkrishna184 Sir, Glad that the answers presented has helped you.

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshatkiit on: 1/9/2016 [Member] Starter | Points: 25

Up
-1
Down
Please refer this:
http://www.dotnet-tricks.com/Tutorial/mvc/QHQT270712-Understanding-ViewModel-in-ASP.NET-MVC.html

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response