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
0 answers

How do you bind a nested viewmodel list with a custom modelbinder?

I'm trying to bind a viewmodel with a dynamic list of nested viewmodels. I figured out on how to bind 1 viewmodel that is nested. But how do I bind a list of them? My classes: public class PracticeViewModel { public List
Ian
  • 67
  • 2
  • 14
0
votes
1 answer

MVC3—Trouble binding complex model

I need to update a company class with an IList of addresses. These are my Data Models. // Entity class Company — managed by Nhibernate public class Company { public virtual IList
_addresses { get; set; } public Company() { …
0
votes
1 answer

Reuse DisplayAttributes with view model properties

Is there a way to use the DisplayAttribute values of an entity within a view model? public partial class Catalog { [Display(ResourceType = typeof(Resources), Name = "ID")] public string ID { get; set; } [Display(ResourceType =…
Jordan
  • 9,642
  • 10
  • 71
  • 141
0
votes
2 answers

How do I only update properties on the original (DB) object that have been changed in the view model?

For example, I have a DateCreated property on my Product and ProductDetailModel classes. Yet, on my Edit view, I have no DateCreated input, or any kind of storage. When I edit a product with a DateCreateded of 2013/03/17, the DateCreated that is…
ProfK
  • 49,207
  • 121
  • 399
  • 775
0
votes
1 answer

ASP.NET with Knockout variable length list with combobox - how to bind?

With the following ASP.NET models public class User { public string Name { get; set; } public LEmail LEmail { get; set; } } public class LEmail { public IList Labels; public IList Emails; } public class…
0
votes
1 answer

MVC razor layout - modify from view

This is my layout page: @ViewBag.Title @Html.ActionLink("Home", "Index", "Home", null, new { @class = "selected"}) …
0
votes
1 answer

Multiple models in view error

I have a view pages that have different partial views with different models. I created a model class that will call other classes so i can use it on the main view page. But my problem is that when i try to change the password it gives me an error…
BB987
  • 181
  • 3
  • 14
0
votes
1 answer

How to use Knockout.js in asp.net mvc Razor correctly and sufficiently?

i try to learn knockout.js on asp.net mvc razor. i have been coding below code to learn and test myself But View side throws me a js error. Error occurs on "var model = @Html.Raw(Json.Encode(Model));" Error : Microsoft JScript run-time error:…
loki
  • 2,926
  • 8
  • 62
  • 115
0
votes
1 answer

ViewModel nested reference: performance issue?

I've a doubt, I admit I'm a beginner in c# and software architecture. I'm working on an ASP.NET MVC4 + EF5 and I'm trying to structure my app using a three tier architecture. In my BL I created those two viewmodels: Word namespace BL { public…
Davide
  • 1,305
  • 3
  • 16
  • 36
0
votes
1 answer

ASP.NET MVC 3 + Serializing a collection displayed into
My ViewModel contains a collection of some object (IEnumerable). The items of the collection are displayed on rows into a tag. When I submit my form, it's triggering submit jQuery function to validate itself. I need to get the values from that…
0
votes
1 answer

ASP.NET MVC 3 - Content loaded into ViewModel is lost after callback

I make a callback jQuery function to fill some collections into my ViewModel with values. When I call this function again, the ViewModel loses the content populated in the first callback. // ---------------------------------------------------- //…
Kiwanax
  • 1,265
  • 1
  • 22
  • 41
0
votes
3 answers

Populating mvc4 viewmodel with multiple List<>

I have a list of 22 categories with about 8 menuItems per category, but my viewmodel ends up with only the last item in the list. I'm having a hard time seeing where the problem is. At this point I'm sure the problem is in how I'm populating the…
NNassar
  • 485
  • 5
  • 11
  • 25
0
votes
1 answer

MVC two views in one model

I'm trying to combine two views in one model. But I cannot get it too work! Can you help me? Models: public class Player { public int playerID { get; set; } [Required] [Display(Name = "Spelernaam:")] public String playerName { get;…
Bvweijen
  • 73
  • 1
  • 8
0
votes
2 answers

How do I populate HTML content with new values once data has been changed on postback?

I have MVC3 razor application. Once I'm submitting a form and in Action i'm changing ViewModel content, i can't see new values populated. There was a topic about that in MVC2 where guys told that it may be fixed in…
Sergejs
  • 2,540
  • 6
  • 32
  • 51
0
votes
2 answers

How can you do multiple saves of a model in one submit?

I have a model: public class CustomerAttributes { public Int Id { get; set; } public string value { get; set; } } my create view looks like this:
@Html.Label("Name")