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

MVC viewModel user defined fields

I have the following: public class myViewModel { [DisplayName("User ID")] [DataType("string")] public MyCustomDataType UserID { get; set; } } I want to define MyCustomDataType as a user defined data type and have my getter and setter handle…
user2708543
  • 39
  • 1
  • 5
0
votes
1 answer

Buddy ViewModel with LINQ Join

SOS! What I am trying to achieve is for the logged in person, to see the users he or she is supporting (buddying). I am now trying to fully embrace ViewModels to coagulate views. I am using simplemembership MVC4 with Mysql. I have a…
Diin
  • 565
  • 11
  • 41
0
votes
0 answers

Display content from various sources

What is the best way to display content from multiple sources(websites)? For example, Display news from various news sites to your site. Not links but actual content. I want to automate this process and avoid any manual intervention. For Now I have…
user793468
  • 4,898
  • 23
  • 81
  • 126
0
votes
1 answer

Should I have each ViewModel for each entity in my ASP MVC project?

I have read many by many solution but i can't understand deeply about what or when i use View Model? For example, when i have a Register form for User to register, i want to hava an field Confirm Password, but i don't think should add it into the…
Luffy
  • 63
  • 2
  • 9
0
votes
2 answers

Returning viewmodel from view gives an ampty object in the controller

I'm working on a small project. The intention is to maintain the presences of a couple of users on some specific dates. This dates are first chosen by the user. Therefor I use a view model. This will provide all possible data with a check box in a…
0
votes
1 answer

View model linked to data model by constructor

I don't have any other way of describing it then how I did it in the title. I have a view model that looks like this: public class CreateArtistModel { public IEnumerable Cultures { get; set; } public…
reaper_unique
  • 2,916
  • 3
  • 28
  • 48
0
votes
1 answer

Using Automapper to Edit selected fields of a model MVC4

I am trying to update selected fields using a viewmodel(OApplyIDViewModel) of the original model(OApply). When I run changes are not effected. I will appreciate help from anyone who is experienced with this. I do not get any error. The form…
Diin
  • 565
  • 11
  • 41
0
votes
1 answer

ListBoxFor is not fully updating the viewmodel on submit

I have been able to create viewmodel like this (please ignore that it includes another viewmodel, that will be fixed after I solve my current problem :) ): public class UserViewModel { #region Variables private SecUserViewModel user; …
Erchi
  • 139
  • 1
  • 12
0
votes
2 answers

ASP.NET MVC Set texts in the View or in the Controller

What is the best practice in MVC (for testing, SOC and scaffolding) for setting texts (for exemple page title, h1,h2..) Is it better to do it in the controlle, fill a viewmodel and send it to the view or directly typing texts in the view? Also I…
riadh gomri
  • 869
  • 1
  • 15
  • 21
0
votes
2 answers

How can I pass the ViewModel back to the same page

I am trying to get a HTTPPost working for a comment section of a video page but am having some difficulty on postback. The save is being recorded to the database but on reload of the page I am not able to find the @Model.SelectedMediaItem.Name…
Jay
  • 3,012
  • 14
  • 48
  • 99
0
votes
1 answer

ASP.NET Razor ViewModel property is modified somewhere

I have an extremely simple Controller + View public ActionResult Edit(string username) { return View(ComponentFactory.GetAdapter().Get(username)); } and @model BAP.Models.UserList @using GrmanIT.Utils.Web @using…
peter
  • 14,348
  • 9
  • 62
  • 96
0
votes
2 answers

Asp.Net MVC Adding two viewmodels to a third

I have two viewmodels, VM1 and VM2 - I want to add these to a third viewmodel, so I can send two tables of information, to my view - but I'm struggling. My viewmodels are: public class VM1 { public string contactf { get; set; } public string…
Mark
  • 7,778
  • 24
  • 89
  • 147
0
votes
1 answer

Return null value after page PostBack in Mvc4

I want to create Invoice Create View. My viewModel as follow: public class InvoiceCreate { public IEnumerable InvoiceItems { get; set; } public IEnumerable Recipients { get; set; } public Sender Sender { get;…
0
votes
1 answer

Can a 'ViewModel' hold 'DomainModel' type property

In asp.net MVC 4, I have 2 DomainModels Product Order and a related ViewModel OrderDetailsViewModel In my "OrderDetailsViewModelMapper" mapper file I am manually mapping these 2 DomainModels to my ViewModel. Mapper file…
0
votes
2 answers

Object reference not set to an instance of an object in view model

I get this error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it…
Anna Marie Rapa
  • 119
  • 1
  • 3
  • 13