{"id":2835,"date":"2014-02-22T01:02:03","date_gmt":"2014-02-22T01:02:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/22\/problem-about-viewmodel-collection-of-common-programming-errors\/"},"modified":"2014-02-22T01:02:03","modified_gmt":"2014-02-22T01:02:03","slug":"problem-about-viewmodel-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/02\/22\/problem-about-viewmodel-collection-of-common-programming-errors\/","title":{"rendered":"problem about viewmodel-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3526437b7c2458590ad290320a6397e8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmarcind<br \/>\nasp.net-mvc viewmodel viewdata asp.net-mvc-3<br \/>\nIn my understanding, the ViewModel pattern was designed to pass all the relevant data to View because 1) the view shouldn&#8217;t perform any data retrieval or application logic and 2) it enables type-safety, compile-time checking, and editor intellisense within view templates.Since dynamic expressions are defined at runtime, does this mean we don&#8217;t get any of the 2)&#8217;s goodies?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/30fa552715430e808849c430bcd49711?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBoas Enkler<br \/>\nviewmodel mvvm-light<br \/>\nIn our application customers can design their ui on their on. For this we load the generated XAML at runtime.We use MvvmLight as Mvvm Framework.But I&#8217;m not sure what the best way is to get some kind of a dynamic view model.So if the customer wants a new Datafield it should be aviable in the model.My idea is to dynamically generated and compile a model assembly or to have converters which get their data from a Dictionary which is placed on the viewmodel.Are there any better ideas, or some experie<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/W8aQL.jpg?s=32&amp;g=1\" \/><br \/>\ngabe<br \/>\nasp.net-mvc asp.net-mvc-3 viewmodel access-modifiers strongly-typed-view<br \/>\nI have some internal automatic properties in my view model but my strongly-typed view doesn&#8217;t see them. Everything is in the same assembly, so why is this happening?public class MyViewModel {public int PublicProperty { get; set; }internal int InternalProperty { get; set; } }.@*My view*@ @model MyViewModel@Model.PublicProperty@Model.InternalProperty @*Causes compilation error*@<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/T5dj5.png?s=32&amp;g=1\" \/><br \/>\nMike Kantor<br \/>\nasp.net-mvc razor viewmodel<br \/>\ndepending on configuration at each site, some fields on a form may or may not be required. Can I apply the [Required] attribute to fields of my ViewModel in code? I&#8217;d like to take advantage of all the conveniences of form validation, but I can&#8217;t hard-code the [Required] attribute.<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f8689490ebef99f48a510d9f5975251b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatt Mangold<br \/>\nasp.net-mvc asp.net-mvc-3 dynamic views viewmodel<br \/>\nTraditionally, I have built MVC applications using view models with Data Annotations attributes, and I dynamically render the views using editor templates. Everything works great, and it really cuts down on the time it takes me to build new views. My requirements have recently changed. Now, I can&#8217;t define the view model at design time. The properties that will be rendered on the view are decided at run time based on business rules. Also, the validation rules for those properties may be deci<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/449c91d2d17c5ff83124dc244913e22e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJackson Dean Goodwin<br \/>\nwpf binding user-controls window viewmodel<br \/>\nI have a portion of a Window that should display one of several UserControls. Each UserControl presents the same data, only in a different format, arrangement, and style. The particular UserControl that will be presented in this section of the Window should be determined by a single setting that is stored in the ViewModel of the Window.How can I make it so that the program end user can change the UserControl that is displayed in the Window at run-time?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/458e10159496fb9f3cac80ed1bc8dbed?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBrendan Hill<br \/>\nc# mvc viewmodel strong-typing<br \/>\nI see a lot of posts about strongly typing the View&#8217;s model data.I am interested in somehow strongly typing the View itself.It concerns me that a controller action returning View(xyz) could crash at run-time, if the view&#8217;s model type changes, or the name \/ location of the view itself changes. In my opinion, the loose coupling of the MVC framework goes too far in this specific area, becoming counterproductive in a RAD environment. (not getting immediately notification of breaking changes)Is there<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f7b429cb27e642aac8508c32dc7ea582?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFrankCap<br \/>\nc# windows-phone-7 viewmodel webclient<br \/>\nI have a refresh button to update news in my WP7 application. When I double or triple click on the refresh button I am getting an error&#8221;WebClient does not support concurrent I\/O operations&#8221; .I think thats because It is sending the request triple times and making it crash. Here is my Click code.private void NewsRefresh_Click(object sender, RoutedEventArgs e){var vm = this.DataContext as MainPageViewModel;if (vm != null){vm.UpdateNews();}}How can I turn it as &#8220;if It is busy cancel the process&#8221;.<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/abf5213e111a93b85594b1c238a19745?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNaser Asadi<br \/>\nwpf constructor viewmodel<br \/>\nhow can I datatemplate a UserControl with a ViewModel with a NON-Empty constructor ?public PersonViewModel(Person person) {_person= person;\/\/ do some stuff }Binding this in Xaml will crash as the Ctor is not empty. But as I use parent\/child relations with the ViewModels I have to pass the person object to the constructor of the ViewModel&#8230;How do you cope with that situation?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nasp.net-mvc razor dictionary checkbox viewmodel<br \/>\nI&#8217;m using MVC 4, .Net 4, and Visual Studio 2012.I&#8217;m trying to use a fairly complex model with one of my views, and I&#8217;m having serious trouble getting it to bind properly.The model wraps a Dictionary with integer Keys, and Values that are Lists of Lists of bools.Basically, a search was done on items indicated by the integer, each item had several search terms, and for each of those terms we have a list of results. I display the results on a page, and have a checkbox next to each result. For each<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f10a8776b856dd7dfbc7fbf8d95c910b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ngarfbradaz<br \/>\nasp.net-mvc-3 controller viewmodel<br \/>\nEDIT FOR SOLUTION:The answer can be found here:http:\/\/forums.asp.net\/p\/1794394\/4941748.aspx\/1?p=True&amp;t=634704481730535356 BUT please see the below from Ricardo as well.I&#8217;ve got a Controller\/View called LedgerUser. I have a ViewModel called LedgerViewModel which contains an instance of LedgerUser and SelectList for instances of UserType and a property called UniqueId which i use for Images. Now when i POST the form back from my Create View I get the following error:The model item passed into<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/225d5b8f09b70d69569b10be9860c546?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nvon v.<br \/>\nasp.net-mvc asp.net-mvc-3 viewmodel asp.net-mvc-viewmodel<br \/>\nWhen I click submit in order to create an account the following error is displayed. I can&#8217;t find why it is giving the following error. Also I tried to use breakpoints and debugging but it was uselessNo parameterless constructor defined for this object.Description: An unhandled exception occurred during the execution ofthe current web request. Please review the stack trace for moreinformation about the error and where it originated in the code. Exception Details: System.MissingMethodException: No<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/38609d2b5ebabaeed243a9730c957ccc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nXaxum<br \/>\nc# asp.net-mvc-4 viewmodel<br \/>\nI have a viewmodel which needs data from two models person and address:Models:public class Person {public int Id { get; set; }public string Name { get; set; }public int Age { get; set; }public int Gender { get; set; } }public class Address {public int Id { get; set; }public string Street { get; set; }public int Zip { get; set; }public int PersonId {get; set; } }The Viewmodel is as suchpublic class PersonAddViewModel {public int Id { get; set; }public string Name { get; set; }public string Street<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/055494e06e9af42502916ce7be46e6ab?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nscapegoat17<br \/>\nasp.net-mvc-3 viewmodel<br \/>\nI am working on creating a datagrid in ASP MVC 3 where I have two tables in one view. Each table is being used from its own Model. Therefore, I would have to call two Models into one View which does not seem as simple as I wish it was. I am pretty new to MVC and I was looking through Stack and found this link: Two models in one view in ASP MVC 3Which seems to be the direction that i would want to go&#8230; I think.Here is the code for my first model:[Table] public class Model1 {[Column(IsPrimaryKey<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cfeb4477d768950c3cd6a469a60e6af4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBillPull<br \/>\njavascript knockout.js viewmodel knockout-mvc<br \/>\nI am trying to create and initialize some sort of master view model that contains common view models that might be run on every page and page specific models that are appended on page load.var MasterViewModel = {commonViewModel1 : CommonViewModel1(),commonViewModel2 : CommonViewModel1() };var commonInit = function() {\/\/ Populate View Model DataMasterViewModel.commonViewModel1 = initCommonViewModel1();MasterViewModel.commonViewModel2 = initCommonViewModel2();\/\/ Apply common view model bindingsko.<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/10eb695056a6cebba8a9a2b74b3ee8fa?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPedro del Sol<br \/>\njavascript ajax asp.net-mvc-3 viewmodel knockout.js<br \/>\nI&#8217;m looking for advice on how to populate the viewmodel passed to the view after a list is retrieved and an item selected in a dropdown list. Note that I also have a client side viewmodel that is used for the Ajax\/Knockout client code but this is not the view model that I am trying to populate. I may have to map from one view model to the other but I&#8217;m not sure if that is the correct solution.View &#8211; Form In my form I am using Knockout and JavaScript for my dropdowns. How can I populate the v<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/22affb12c8e74ae9b09d6f94c799a60f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAlfeG<br \/>\njavascript data-binding mvvm viewmodel knockout.js<br \/>\nLooking for a good example of how to set up child models in knockoutjs. This includes binding to child events such as property updates which I haven&#8217;t been able to get working yet. Also, it would be better to bind to a single child in this case instead of an array but I don&#8217;t know how to set it up in the html without the foreach template.http:\/\/jsfiddle.net\/mathewvance\/mfYNq\/Thanks.&lt;div class=&#8221;editor-row&#8221;&gt;&lt;label&gt;Price&lt;\/label&gt;&lt;input name=&#8221;Price&#8221; data-bind=&#8221;value: price&#8221;\/&gt;<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a717291747c76567bb0f086e15ae6e43?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGilles<br \/>\nc++ opengl viewmodel transformation<br \/>\nI am trying to understand the glLookAt function. It takes 3 triplets. The first is the eye position, the second is the point at which the eye stares. That point will appear in the center of my viewport, right? The third is the &#8216;up&#8217; vector. I understand the meaning of the &#8216;up&#8217; vector if it is perpendicular to the vector from eye to starepoint. The question is, is it allowed to specify other vectors for up, and, if yes, what&#8217;s the meaning then?A link to a graphical detailed explanation of gluPerst<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6b4aab6a5636a6d58cee545a18eff34b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCHAT_2013<br \/>\nknockout.js viewmodel<br \/>\nI have the following viewmodel defined:function BookCartViewModel() { this.Books = ko.observableArray([]); this.Categories = ko.observableArray([]); }var Book = function (data) {this.ISBN = ko.observable(data.ISBN);this.BookID = ko.observable(data.BookID);this.BookName = ko.observable(data.Name);this.Price = ko.observable(data.Price);this.Publisher = ko.observable(data.Publisher);this.PublishedDate = ko.observable(data.PublishedDate);this.Authors = ko.observableArray(data.Authors);this.Category<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6ad1f6a46c40fa7c3dca0054f76beb9e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNanda<br \/>\nasp.net-mvc-3 enums viewmodel<br \/>\nI have a database first model, where is a Person entity, like this:public partial class Person {public System.Guid personID { get; set; } public string firstName { get; set; } public string lastName { get; set; }public string sex { get; set; } \/\/ since in the DB it is char(1), default = &#8216;F&#8217; }I defined a public enum for sex selection:public enum Sex {M, F}which I want to use it to select the sex of the person and to render it as a radio button group.I followed this solution: pass enum to html.rad<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>marcind asp.net-mvc viewmodel viewdata asp.net-mvc-3 In my understanding, the ViewModel pattern was designed to pass all the relevant data to View because 1) the view shouldn&#8217;t perform any data retrieval or application logic and 2) it enables type-safety, compile-time checking, and editor intellisense within view templates.Since dynamic expressions are defined at runtime, does this mean [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2835","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2835"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2835\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}