Questions tagged [asp.net-mvc-viewmodel]

View model is a class, that represents data model used in specific view.

View model has many roles:

  • View models documents view by consisting only fields, that are represented in view.
  • View models may contain specific validation rules using data annotations or IDataErrorInfo.
  • View model defines how view should look (for LabelFor,EditorFor,DisplayFor helpers).
  • View models can combine values from different database entities.
  • You can specify easily display templates for view models and reuse them in many places using DisplayFor or EditorFor helpers.
497 questions
5
votes
1 answer

Using PagedList with a viewmodel MVC 3

I am trying to implement IPagedList with a viewmodel, my main view declaration is @model PagedList.PagedList Then i have a Display Template which has the following declaration @model…
Liam
  • 455
  • 2
  • 7
  • 22
5
votes
1 answer

MVC5 ViewModel Not Posting back to Controller

So, I have an issue with a controller/view/viewmodel. It's similar to this issue I think. Basically, I have a viewmodel that I send to a view from my controller. There are items that display and then some additional fields for the user to…
5
votes
1 answer

Using the ODATA $expand query option with WebAPI and a ViewModel

This question is very similar but does not give me what I need. I am using Entity Framework 6. My database has two tables, Customers and CustomerTypes. I have created a ViewModel for each. A customer can have a type: public class Customer { …
5
votes
3 answers

ViewModels with asp.net mvc 4 and EntityFramework whats the Point

I'm debating with myself whats the point in creating ViewModel classes in a project which uses Entity Framework? I currently have a project which uses EntityFramework. My solution is structured basically like this: UI project (contains controllers…
5
votes
2 answers

To insert Data into Multiple Tables using MVC ASP.NET

I am new to MVC ASP.NET. Although this might have been solved in the past but I still can't get a complete Solution to my problem. Problem : I have two tables Video Columns are : VideoID, FlimName, Description VideoDetails Columns are :…
Mangesh Kaslikar
  • 591
  • 3
  • 13
  • 23
5
votes
1 answer

MVC3 Custom Validation error message doesn't display when using ViewModel

SUMMARY Question: Why doesn't the custom validation error message show when using a ViewModel. Answer: The custom validation should be applied to the ViewModel not the Class. See the end of @JaySilk84's answer for example code. MVC3, project…
Joe
  • 4,143
  • 8
  • 37
  • 65
4
votes
4 answers

asp.net mvc - nearly identical ViewModels

I am building a web application with ASP.NET MVC and am still a beginner with this technology. I have learned that it is best practice to have a ViewModel for each View. I can understand why this is a good idea. However, in my situation it seems to…
bjoeg
  • 53
  • 4
4
votes
2 answers

ASP.NET MVC + Entity Framework - How to deal with DTO's and ViewModel's

I'll try to describe a problem that I see very often in my workplace, but I couldn't find a way or a reasonable solution to it. I searched a lot about this and all I could find is what I already have implemented. The scenario is this: I have an…
jpgrassi
  • 5,482
  • 2
  • 36
  • 55
4
votes
1 answer

Does ViewModel supports Nested Models ? Can Virtual property can be applied to viewModel?

I am using .net 4.5.1, visual studio 2013. I have created a invoice create page with ViewModel -CreateInvoiceViewModel. public class CreateInvoiceViewModel { public int EntityID { get; set; } . . public…
anand
  • 1,559
  • 5
  • 21
  • 45
4
votes
2 answers

Why doesn't my view get rendered when my action is entered from a Ajax call?

I have a Ajax call that hit my controllers action 'SearchFromWithin' and I want to know why the view doesn't get displayed. I can enter the view and step through it, but the screen just stays as the same. It doesn't display the new view. Here is my…
chuckd
  • 13,460
  • 29
  • 152
  • 331
4
votes
2 answers

asp mvc list product details in view using View Model

I am trying to list single product details in a view. The product specification changes dynamically because specifications are added row-wise in table, which means we can add huge number of specifications for each product (as done in ecommerce…
Shaiju T
  • 6,201
  • 20
  • 104
  • 196
4
votes
2 answers

MVC handling Collection Item Index in Partial view model

I Have a ViewModel with a collection inside such as: public class CreateCampaignViewModel : ControlPanelViewModel { [RequiredField] public string Name { get; set; } public List Advertisements { get; set; } …
4
votes
1 answer

Null Reference Exception when i use navigation property in model class

I try to add new entity in database in controller action. This is my model class public class Product { public int ProductID { get; set; } [Required(ErrorMessage = "Please enter product name")] public string Name { get; set; } …
alinaish
  • 456
  • 2
  • 7
  • 18
4
votes
5 answers

ViewModel not being passed back to controller in POST method

Simple problem, but I can't figure out what is missing. I have a simple ViewModel (it'll get bigger): public class TigerTrackingViewModel { public TigerTrackingViewModel() { this.TigerTrail = new TigerTrail(); } public Guid…
ledgeJumper
  • 3,560
  • 14
  • 45
  • 92
4
votes
7 answers

required attribute not working in asp.net mvc

I have a simple strongly-typed view. @model GoldForGold.Models.LogonModel @{ ViewBag.Title = "Logins"; Layout = "~/Views/Shared/_Layout.cshtml"; } Logins @using (Html.BeginForm()) { Account Information @Html.LabelFor(m =>…
user2465036
  • 351
  • 2
  • 11
  • 24
1 2
3
33 34