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
0
votes
1 answer

validation failing on dropdown MVC

I am using code-first with EF. Validation seems to be failing on a dropdown list with the error System.NullReferenceException: Object reference not set to an instance of an object. This happens when I save a record and I intentionally leave controls…
0
votes
1 answer

Call a method in Linq to EF

In order to create a ViewModel, I tried to call a method GetName() to find the FirstName and LastName for UserID and then add it to the model. But the error tells "Linq to Entities does not recognize the method". How do I accomplish this in another…
0
votes
4 answers

MVC ViewModel errors

Goal: To create a re-usable drop down menu that lists my website's administrators, managers and agents. These types of users are defined by the .NET Simplemembership webpages_Roles and webpages_UsersInRoles tables. So Far: I have a UserProfile table…
Julian Dormon
  • 1,767
  • 4
  • 32
  • 58
0
votes
3 answers

MVC2 controller not receiving all data from view on submit

I have an app that calls a web service to display import records based upon criteria entered by the user. Each "import" can have 0 to many PurchaseOrder, 0 to many Containers, 0 to many Products, 0 to many Invoices. the View (displaying the inquiry)…
0
votes
1 answer

Service layer ModelState not updating in .net Web API

I'm implementing an MVC solution that has some Web API endpoints for various data queries. I'm using the techniques described in this post to separate my validation concerns to a Services layer. This post has a TL;DR at the end if you want to skip…
0
votes
2 answers

Passing values to view in Asp.net MVC3

I have two tables Date and Song. Where DateId is foreign key to Song table. - Date: DateId Date - Song: SongId DateId Title Here is the function: public ActionResult Index() { var song =…
NoviceMe
  • 3,126
  • 11
  • 57
  • 117
0
votes
2 answers

Controlling the default value and format of Form elements Generated using view Model

I am generating Form elements using a Model Class as below Public Class BookAppointment Property DoctorNin As Integer Property PatientNin As Integer Property BookingDate As Date Property Doctors As IEnumerable(Of SelectListItem) End…
mrN
  • 3,734
  • 15
  • 58
  • 82
0
votes
2 answers

validate the individual property of viewmodel using data annotation

I am trying to built multiple file upload using view model and data annotation. Following is view model: public class UploadNewsModel { [File(AllowedFileExtensions = new string[] { ".jpg", ".gif", ".tiff", ".png", ".pdf" }, MaxContentLength = 1024…
CodeManiac
  • 974
  • 8
  • 34
  • 56
0
votes
1 answer

Can't populate ViewModel

MVC3 project. I have several classes: Account, Address, Phone etc. which I set up in a view model namespace ViewModels { public class AccountVM { public Account Account { get; set; } public Address Address { get; set; } public Phone…
Joe
  • 4,143
  • 8
  • 37
  • 65
0
votes
2 answers

MVC c# ViewModel with table object

I have a viewmodel as such public class NoteViewModel { public tblNotes tblnote { get; set; } } In my controller, I do the following next after doing a build so my controller knows about the viewmodel: NoteViewModel…
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
-1
votes
1 answer

How do I disable and enable comboBox in WPF based on some other process?

I have a situation in which I have to dither combo box while some process is being completed. This snippet is of the Combo Box XAML (ItemSearchView.XAML)..
-1
votes
1 answer

IEnumerable vs DataTable serverside

Everytime I pass data I use IEnumerable from the controller to the view. But Today I was thinking about what would happen if there are a thousand or millions rows in the table,... Will it overload the processor? or Will it use all the ram?. So now I…
-1
votes
1 answer

Editing and saving from a ViewModel.

This seems to be a common question. I have looked at many examples however I must be missing something somewhere. Below is my code for the 'ViewModel', and 'Controller'. ViewModel: public class EditAddressViewModel { public Guid AddressUI {…
S.Purtan
  • 125
  • 1
  • 2
  • 11
-1
votes
1 answer

How to add multiple models to a single view using ViewModel in ASP.NET MVC 5?

I am trying to add multiple models to a single view using a ViewModel with Code First approach in Asp.Net MVC 5. Each domain model has its own CRUD operations. I want the ViewModel to have CRUD operations for each domain model. The…
-1
votes
1 answer

How to use generic types in mvc model view

I want to create a partial view which will be used several times with differents entities. It seems that the way to do that is to implement interfaces and use generic types. But after a lot of search I still doesn't understand how to use that in my…
Manta
  • 490
  • 5
  • 18