ViewModel Microsoft Tutorial Material

Dean Everhart 1,496 Reputation points
2023-05-06T14:35:21.2533333+00:00

Premise

I am looking for basic Microsoft tutorials covering the topic of ViewModels for .net 6 MVC. I see none listed for .net 6 MVC (below). A Google search yields one Microsoft Tutorial for ViewModels for .net 3 MVC (the Music Store tutorial) (below) but I see no actual reference to ViewModels in the tutorial.

Question(s):

  1. Would someone please help me find basic .net 6 ViewModel tutorials on the Microsoft website?
  2. If there are none, would you recommend any other resources covering the topic of basic ViewModels?

Microsoft Re: ViewModels:

Get started with ASP.NET Core MVC - no tutorial on ViewModels

User's image

Part 3: Views and ViewModels - ViewModel tutorial listed with no material on ViewModels

User's image

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,134 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2023-05-06T23:43:25.78+00:00

    when using MVC, there is the View Model, the class instance passed from the controller to the view. This is how the controller passes typed data to the view. The ViewBag (a dictionary collection) can also be used.

    when posting to the action, there is also the binding model. the post data is mapped to an instance of this model.

    the movie example uses Entity model for the view model. this is a bad practice. View model should only have what is needed for the view render.

    It is also common to use the View Model for the post back model. But this can lead to over binding issues. The simpler you keep the view model, the less of the issue this is. You should avoid including data in the view model that you don't want displayed in the html.

    You should also avoid round tripping hidden data. if you do this you should encrypt the data first.

    Always assume the user is using browser tools to hack the data.

    0 comments No comments

0 additional answers

Sort by: Most helpful