FAQ Database Discussion Community


Asp.Net MVC 4 view model and domain model ids

c#,asp.net-mvc-4,design-patterns,domain-driven-design,viewmodel
Our system runs on multiple servers. All the tables in our system uses GUID as the Primary Key and Foreign Key fields. This is however our old system and it it going through a brand new rewrite. The motivation to use GUID in the old system was for migration of...

EXTJS 5 Can I have a tree store in stores property of view model?

javascript,extjs,mvvm,viewmodel
I have this simple mvvm example: https://fiddle.sencha.com/#fiddle/j8m When I console.log the viewModel from the controller, stores appear in the data attribute, calling viewModel.getStores() returns me null. I don't get it :/... Here is the same code as in the fiddle: Ext.define('MainViewModel', { extend: 'Ext.app.ViewModel', alias: 'viewmodel.mainviewmodel', stores: { todoAccountsStore: {...

How use viewModels + Entity Framework? Is necessary add a migration?

c#,asp.net-mvc,entity-framework,viewmodel,asp.net-mvc-viewmodel
I am using asp.net mvc 4 + entity framework and for the first time I'm using ViewModels. I'm reading this tutorial: http://www.asp.net/mvc/overview/older-versions/mvc-music-store/mvc-music-store-part-8 After step in that it creates classes viewmodel, he's going to create the controller, but does not explain whether to create a migration to add these classes in...

using a method from viewmodel on a buttonclick event in view

c#,wpf,mvvm,methods,viewmodel
I'm new to mvvm and I'm trying use a method "SaveAll"that saves the observablecollection to the database and I want to call it from a buttonclick event in code behind the view, but it doesn't seem to be possible. This is the code I have so far. The error happens...

Handling View Model in Post Method of Edit page

asp.net-mvc,viewmodel
I am trying to modify the activity edit page so that I can involve more information. To simplify, I have the following. Model public class Activity { public int ActNo { get; set; } public string ActName { get; set; } public virtual ICollection<Attendance> Attendances { get; set; } }...

Convert meters to kilometers and format the value in Viewmodel

c#,asp.net-mvc,viewmodel
I have the Viewmodel: public class PartnerSearchResultVM { public int Id { get; set; } public string Name { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } public double Distance { get; set; } public string Classification { get; set; }...

WPF TextBox not updating in UI every time PropertyChanged is raised

c#,wpf,xaml,binding,viewmodel
I saw a lot of other questions around this, but none seemed to pertain, since my binding is working, but just not every time. I have a TextBox in my XAML. <TextBox TextWrapping="Wrap" Text="{Binding ProgressMessages, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> It is bound to a Dependency Property () in the ViewModel. private string...

Viewmodel always null following file upload

c#,asp.net,asp.net-mvc,viewmodel
I am creating a page in Asp.Net MVC where a user can upload a file, along with details about the file from textboxes. For this I use a viewmodel, and a very simple method configuration. The page is populated correctly by the [Get] Method, and the user can choose the...

How to pass a joined table to a view in MVC?

c#,asp.net-mvc,controller,viewmodel
I am building a project in Mvc and having some trouble. I have worked with viewmodels countless times before, and the relationship between Controller-View, but this problem has stumped me. I am wanting to pass a joined table to the view, and im not sure how to go about this....

C# select data into the viewmodel using linq

c#,linq,viewmodel
I have a viewmodel public class CompanyDetailVM { public string CompanyName { get; set; } public IEnumerable<Comments> Comments { get; set; } } I want to retrieve all the data coming from XML, I cant figure out how to get list of comments too (Comments model consist of CommentText, DateTaken)....

Regarding how MVC and ViewModels are used [closed]

c#,asp.net-mvc-4,razor,viewmodel
I have Model POCOs that just store the usual information from the user and is used to submit and pre-populate the form elsewhere. I have ViewModels(is this the right term?) that populate dropdownlists, sometimes by gathering information from XML configuration. I combine all these classes into one superclass that is...

Creating control instance in viewmodel

c#,wpf,mvvm,richtextbox,viewmodel
In my program I'm trying to design an output window to display logging information. For right now I'm binding to a string and updating the info as soon as log data comes in. Ex: <FlowDocument> <Paragraph> <Run DataContext="{Binding}" Text="{Binding OutputText}"/> </Paragraph> </FlowDocument> (The flow document is inside a rich textbox)...

The XAML code expect my Command in different VM

c#,wpf,xaml,viewmodel
On the main window xaml, I have a Frame that will host 2 pages, like this <Window x:Class="Monitor.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" FontSize="14"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="48"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Frame Content="Frame" Grid.Row="1"...

Show ViewController from inside plugin

ios,plugins,touch,viewmodel,mvvmcross
I'm having trouble to show a view model (created inside the plugin) from inside the plugin. For example, I don't want to show it like a modal view, I want to show it whatever the app is developed. If it is developed using UINavigation, then push it, if it is...

How to resolve System.Reflection.TargetInvocationException' error?

c#,viewmodel,mvvm-light,ioc-container,windows-universal
I'm using the MVVM Light libraries in my application which provides an Ioc container, called the ViewModelLocator. But when I set up a second property in the locator for a new View Model, I get a System.Reflection.TargetInvocationException I debugged this by looking at the inner exception, and it seems that...

What does “Stateful” means in Stateful ViewModel in MVVM

.net,wpf,xaml,mvvm,viewmodel
I was reading about some XAML patterns, and there was the Stateful ViewModel, according to what I read it has nothing different than what we as just the "ViewModel". Here's a description for example : Stateful View Model: To create isolation between business logic and presentation, data should be removed...

In asp.net-mvc, How can I insert a class name from my view model for a html.dropdownlistfor

c#,asp.net,asp.net-mvc,viewmodel,html.dropdownlistfor
I have the following code in my view: <%= Html.DropDownListFor(r=>r.Id, Model.MyList, new { @class = "Dropdown hidden" })%> but now I want to only assign the class "hidden" in certain cases so I want to pass that in from my ViewModel to either add the class or to leave it...

How to access View control's from the ViewModel?

c#,design-patterns,mvvm,view,viewmodel
I've come across the situation, where I need access to the controls in the View from the ViewModel. In order to code a method that adds the selected item from a ComboBox to a list. My question is how do I access the View controls from the ViewModel? Is there...

Better Way To Edit A View Model in MVC

asp.net-mvc,viewmodel,model-binding
I actually came up with a working example of how to display (GET) and edit (POST) a view model consisting of three models in MVC. However, my MVC skills are limited and I was looking for suggestions on "the right way" I should be doing this. The part in question...

Linq syntax to set values of Dictionary>

c#,linq,dictionary,viewmodel
What is the Linq syntax to set a list of strings from a dictionary where the long Object.objectid matches the dictionary long? For each person "member" in Members, if the long id matches, I want to add the string value from the List. partial class BandMember { public List<string> summary...

Why “removing any who's ViewModel PropertyType is an interface” when creating the MvvMCross View lookup table

xamarin,viewmodel,mvvmcross,lookup-tables
When creating the default View lookup table in MvvMCross, there is a step "removing any who's ViewModel PropertyType is an interface". (http://slodge.blogspot.de/2013/01/overriding-view-lookup-convention-used.html) Why is this step performed? It's clear, that you can't instantiate an interface, but I can navigate to Interface implementing ViewModels with ShowViewModel<IMyViewModel>(), if I write Mvx.Register<IMyViewModel, MyViewModel>()....

How avoid duplication in a list

c#,random,viewmodel
I'm trying to get a distinct list to my view.I need to select records from a list randomly and put it in to another list.The following code works..But it contain duplication records..How can I overcome this problem? Note: the variable "budget" is a parameter passed in to the controller and...

How to access list of a ViewModel

c#,asp.net-mvc-5,viewmodel
I have the following model; public class Object { public int Id { get; set; } public string Name { get; set; } public Nullable<double> Price { get; set; } public string Description { get; set; } public string Image { get; set; } public Nullable<int> Type { get; set;...

Using server-fetched DTO data in WPF MVVM views that don't necessarily resemble DTOs

wpf,mvvm,model,viewmodel,dto
I am at the beginning of a WPF MVVM project that uses MVVM Light Toolkit. My services in the client consume some external Restful APIs. Here is my general plan so far for transferring server data to view, and I want to know if it needs to change: I will...

Dropdownlistfor MVC 5 in ListView (IEnumerable of Viewmodel)

c#,asp.net,model-view-controller,view,viewmodel
I am making a schoolproject and I'm stuck at a dropdownlist in my view. So here is my ViewModel: using System; using System.Collections.Generic; using System.Linq; using Klimatogrammen.Models.Domain; namespace Klimatogrammen.ViewModels { public class VraagViewModel { public String Question { get; private set; } public String Code { get; private set; }...

Trying to Populate ViewModel List from Linq query MVC “List doesn't contain definiton for …”error"

model-view-controller,viewmodel
I am (trying to) build a multiple choice test application that will pass a list of multiple choice questions (select lists) from the controller to a view. Then populate the view using a foreach loop, post the answers back to the controller, check them and increment the score for each...

Save Form Fields After Failed Validation With ViewModel

c#,asp.net-mvc,viewmodel
I have a C# form which uses a ViewModel. The Get function calls the view like this: return View(viewmodel); In my Post function, I'm validating the form fields and then using this to return to the view: if (!ModelState.IsValid) { ViewData["wo_id"] = wo_id; var viewmodel = new AEO.WorkOrder.Domain.ViewModels.WorkOrderDetailsViewModel(wo_id); viewmodel.GetWOIMDetails(); return...

Cannot figure out view models

c#,asp.net-mvc,viewmodel
I cannot for the life of me figure out how to do a viewmodel correctly. We have two models, tblInventory and tblGlobalhardware, both of which need to be shown on the Details page of an inventory item, based on the InventoryID (Primary key in tblInventory and is a column in...

Cannot implicity List into IEnumerable

c#,asp.net-mvc,controller,viewmodel
My ViewModel public class ViewModelCT { public IEnumerable<SelectListItem> Tests { get; set; } public IEnumerable<string> SelectedTests { get; set; } public Course course { get; set; } } Controller public ActionResult Details(int id) { Course course = functionality.toCourse(functionality.GetCourseById(id)); List<SelectListItem> lsli = new List<SelectListItem>(); ViewModelCT vm = new ViewModelCT(); foreach (SchoolService.Test...

Communication between ViewModels in KnockoutJS

javascript,knockout.js,viewmodel
I'm trying to implement communication between my view models in a knockoutjs driven application. I scaffolded it using yeoman tool, and as you can see it uses AMD: define(['knockout', 'signals', 'text!./nav-bar.html'], function(ko, Signal, template) { function NavBarViewModel(params) { this.route = params.route; } return { viewModel: NavBarViewModel, template: template }; });...

MVC 5 View - Set Javascript variable

javascript,c#,view,asp.net-mvc-5,viewmodel
I am coding a MVC 5 internet application and I have a question in regards to a View. I have a ViewModel variable that holds a decimal value. When the View is displayed, I need to get this decimal value and store it in a javascript function. Here is my...

How to control selection from ViewModel of MultiSelectTreeView

c#,wpf,mvvm,viewmodel,view-model-pattern
I've got a WPF MultiSelectTreeView (downloaded from here: http://unclassified.software/en/source/multiselecttreeview). Now I want to control, which items the user selects. A simple example is that he shouldn't be able to select child nodes of different parents. But there are also more ViewModel-specific use cases. It's easy to achieve this in code-behind...

How to access ShowMessageAsync method of MetroWindow from ViewModel

wpf,mvvm,viewmodel,mahapps.metro
I am using MahApps.metro WPF library with MVVM. I have a ViewModel from which I need to display a Dialog. The MetroWindow has ShowMessageAsync. But what is the proper way to access it from the ViewModel? As I understand I need a View instance but passing that into the ViewModel...

Load up multiple remote data sources for knockout.js data binding

javascript,ajax,knockout.js,viewmodel
I'm working on a knockout.js wizard and need to get data from multiple remote data sources (via AJAX) before I can properly render the drop-down menus in the wizard. Additionally, there are 4 dropdowns and while #1 and #2 can be loaded up first, #3 and #4 depend on the...

WPF use one ViewModel for multiple UserControls

wpf,binding,user-controls,viewmodel,datacontext
I've searched a lot for an answer for this question, but couldn't quite find an answer. I have my main Window and 4 different UserControls. The Window is constructed from all 4 UserControls. I have a class which is the Window's ViewModel. I wish to set the DataContext of the...

Binding ObservableCollection in viewmodel to listbox

c#,wpf,mvvm,binding,viewmodel
I'm very new to MVVM and bindings and I'm trying to learn to work with it. I run into the problem of binding my viewmodel to the view in particular binding an observable collection to a listbox. this is what my viewmodel looks like: namespace MyProject { using Model; public...

Avoid duplicating fields for different forms

c#,asp.net-mvc,asp.net-mvc-5,viewmodel
I've run into this on three projects now. I have multiple forms that reference the same data fields, but have different displays. For the example below I am updating or referencing the AspNetUser table from create new user, edit profile, login etc. If I try for a single base view...

How to supply dynamic data set to a single view using ViewModels

c#,asp.net-mvc,viewmodel
(first time posting and fairly new to MVC) I currently have a MVC/C# application where the user selects a list of ID's and then chooses a Report Type (8 possible different reports calling 8 different database views). I am passing all of these parameters to the controller. Based on the...

Creating a DateTime using AutoMapper

c#,viewmodel,automapper
I am struggling to create a DateTime object from (year, month, day) which is being returned from the database. I am rather new to AutoMapper so a nudge in the right direction would be great. Here is the ViewModel containing the DateTime object and the three values that need to...