viewmodel

Update model with latest autoinc id from database

Hello, which method do you prefer to update my newly saved customer with the last autoincremented Id ? Do you see any disadvantage in one of both methods? CustomerRepository.cs public int AddCustomer(Customer customer) { //.... return lastID; } BillingViewModel.cs //Method 1 SelectedCustomer.Id = _customerRepo.AddCustomer(Sel...

ASP.NET MVC2 Posting a ViewModel mapping to Domain (LINQ) to Submitting changes

I'm using AutoMapper to map between a Linq Domain object and a ViewModel to display an Edit Form to the user which works perfectly. When they click submit I'd like to know the best way to map the ViewModel back to a Linq entity and persist it to the database. The Linq entity I'm using has multiple collections of other entities (ie one-...

ViewModel and binding for dynamically addable comboBoxes

Hi. I didn't find a solution for this but I think it should be doable. I have a number of items in a collection and want to select some of them. Each item has a CanInclude property containing the elements that can be selected if itself is already selected. Item1 CanInclude: Item4, Item5 Item2 CanInclude: Item3, Item4 Item3 CanInclude:...

ViewModel is empty MVC2

Hello all, When I press the submit button and access the Controller my ViewModel is empty. I don't know why this is happening, I have similar code to this on the other views and they do pass through data. Controller public ActionResult DeleteCategory(int id) { var data = _service.GetIndividualCategory(id); ...

Does using ViewModels and references to System.Web.Mvc violate the MVC pattern?

I've seen it all over SO, blogs, and books, where the authors tell you add ViewModels specific to your View in your Model projects as wrappers for your underlying model objects. The idea is to make it very simple and targeted when you go to do model binding to the View. Here is a good example: Rendering and Binding Drop Down Lists using ...

Where to create parametrized ViewModel?

I have recently parametrized my ViewModel's contructor. Before that, I was doing this in my window: <Window.DataContext> <vm:MyViewModel /> </Window.DataContext> The framework instantiated the ViewModel for me. I know I can set DataContext in code but I would prefer a XAML way so designer can display my test data when designing. ...

How to implement a tab control where each tab is a generic paged entity?

Background: I'm trying to implement a tab control. The tabs are as follows: | Funds | Companies | Groups | and are implemented as follows: <ul class="ActionControl"> <li> <%=Html.ActionLink(string.Format("Funds ({0})", Model.Summary.FundCount) , "ResultsList", new {selectedTab = "Funds"} ) %> </li> //...

When is it right to use ViewData instead of ViewModels?

Assuming you wanted to develop your Controllers so that you use a ViewModel to contain data for the Views you render, should all data be contained within the ViewModel? What conditions would it be ok to bypass the ViewModel? The reason I ask is I'm in a position where some of the code is using ViewData and some is using the ViewModel. I...

WPF: Proper configuration for Window with a child UserControl (MVVM)

I am trying to properly accomplish the following. I have a UserControl (ProgramView). It has a viewmodel (ProgramViewViewModel). ProgramView is consumed as a child control within a Window (ProgramWindow). ProgramWindow has a public property ProgramId, so the consumer of the window can specify the desired Program (data entity) to show. Pr...

Technical code into the ViewModel in wpf ?

I have a UserControl with some custom dependency properties bound to a clr property in the ViewModel. The ViewModel has application logic where I deal with the TextPointer/TextRange classes with a FlowDocument. Should I put that stuff into the code-behind of the UserControl or in the ViewModel? ranges.Clear(); TextRange ran...

Should my ViewModel's constructor populate the ViewModel's data?

Should my ViewModel encapsulate the Services needed to populate it? Currently I'm doing it as follows: public PartialViewResult Companies(SearchViewModel search) { search.Summary = _entitySearchService.GetSearchDataSummary(search.SearchExpression); search.PagedCompanies = _companyService.GetPagedEntities<Company>(search.SearchE...

MVC2 sending collections from the view a controller via json.

I've been looking on forums for 2 days now and can't find a good answer so I'll just post it. I appear to be having a problem posting JSON back to the controller to save. The JSON should map to model view but it keeps getting default(constructor)values rather then the values from the POST. We have a series of JS widgets that contain a...

How to use templated helpers with ViewModels?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProductViewModel>" %> <%= Html.DisplayFor(m => m.Product.Name) %> Does not work. It says: "The type arguments for method ... cannot be inferred from the usage. Try specifying the type arguments explicitly." ...

WPF: Command parameter for a delete command in a list

In my viewmodel, I have a list (ObservableCollection) containing items. In the view, this list is displayed in an ItemsControl. In each row, there is a "Delete" button. I want the command behind the button to remove the item from the list. <ItemsControl ItemsSource="{Binding myList}"> <ItemsControl.ItemTemplate> ... ...

MVC2 ViewModel Binding

How do I get properties in my BLL passed down to a ModeView. For example, I have this class in a separate Class Library: [MetadataType(typeof(PersonMetaData))] public partial class Person { [Bind(Include = "PersonId,DepartmentId,FirstName,LastName,Active,DateAdded,DateDeleted")] public class PersonMetaData { ...

Relate view & viewmodel.

<DataTemplate DataType="{x:Type vm:SalesViewModel}"> <vm:Sales> </DataTemplate> Whats the meaing of the above code in wpf resource file? ...

How to get data for a dropdownlist into viewmodel when using AutoMapper/AutoMapViewResult

After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf (both highly recommended!), I began to implement some of their ideas. One of the cool things they do, is not only to use AutoMapper to map your entities to some viewmodel, but automate this with an AutoMapViewResult: public class EventsControlle...

Passing and returing data to a simple grid form using ASP.NET MVC

Hi I have page with a simple table and advanced search form. I pass List<Customers> to the model: View(List<Customers>); So what is best way to pass and return data to the search form? I want to use validation or something but I think passing data through ViewData is not good idea. Any suggestions? ...

MVC 2 View Model Data Problem

Here is my database Structure Languages LangID PK LangName nvarchar(100) Category CatID Pk IsActive Bit CategoryText CatID FK CatName nvarchar(200) LangID Int Language LangID | LangName 1 | English 2 | French Category CatID | IsActive 1 | True 2 | True 3 | True CategoryText CatID | CatName | ...

MVVM Child View Model To Parent ViewModel

Page/ViewModel expose a Tab Control with Couple tab Items on that page. Each Tab Item has their own View Models. First tab load when page loads. How could I pass an object to this tab Item before it loads with the page. View models are independent. Child which is Tab item view model needs to grab property from PageVievModel. ...