viewmodel

Using multiple models in a single controller [closed]

别来无恙 提交于 2019-11-26 18:39:59
问题 I have used EF Designer from database to build my models from a database created for my project. For a single controller, I need to reference multiple models. An example of this is that there is a Users table which contains the user department and office. I need to reference two separate tables DepartmentPermissions and OfficePermissions to determine what data the user is able to see. Here are examples of the auto generated models: //-----------------------------------------------------------

Custom vs User control

こ雲淡風輕ζ 提交于 2019-11-26 17:56:46
问题 I've been reading some explanations about the difference between User and Custom Controls, for example this: http://www.wpftutorial.net/CustomVsUserControl.html I want to create, for example, a simple composition of a datagrid with 2 comboboxes which are responsible to change the values from the datagrid's items. I want to create a specific control for this because I'm going to use it a lot of times. I would like to implement the logic behind and then in the xaml invocation I only have to

Passing complex navigation parameters with MvvmCross ShowViewModel

倖福魔咒の 提交于 2019-11-26 17:33:30
问题 My complex type wouldn't pass from Show to Init method even with configured MvxJsonNavigationSerializer as specified here Custom types in Navigation parameters in v3 public class A { public string String1 {get;set;} public string String2 {get;set;} public B ComplexObject1 {get;set;} } public class B { public double Double1 {get;set;} public double Double2 {get;set;} } When I pass instance of object A to ShowViewModel method I receive this object with String1 & String2 deserialized correctly

Ignore mapping one property with Automapper

我的梦境 提交于 2019-11-26 17:06:38
I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with: Mapper.CreateMap<OrderModel, Orders>(); It generates an exception : "The following 1 properties on Project.ViewModels.OrderModel are not mapped: 'ProductName' I've read at AutoMapper's Wiki for Projections the opposite case (the extra attribute is on the destination, not in the source which is actually my case ) How can I avoid automapper to make the mapping of this property? smartcaveman From Jimmy Bogard: CreateMap<Foo,

Maintain state of a dynamic list of checkboxes in ASP.NET MVC

守給你的承諾、 提交于 2019-11-26 16:37:02
问题 I have a class called "PropertyFeature" which simply contains PropertyFeatureID and Description. It's a proper model created through LINQ to SQL mapped to an SQL Server database table. An example instance/row would be: PropertyFeatureID: 2 Description: "Swimming Pool" The number of rows (PropertyFeatures) can of course grow and shrink, and so I want to dynamically render a list of checkboxes so that the user can select any of them. I can dynamically render the Checkboxes easily enough, with

How to create a strongly typed master page using a base controller in ASP.NET MVC

我们两清 提交于 2019-11-26 15:36:04
问题 Following the NerdDinners example, I am interested in creating a strongly typed Master Page. In order to achieve this, I use a base controller which retrieves the data for the master page. All other controllers inherit this class. Similarly, I have ViewModels for the master page and any other views. The view ViewModel classes inherit from the master page's ViewModel . Question How should a child controller ensure that the master page's data is passed to the View without setting the properties

How can I bind nested ViewModels from View to Controller in MVC3?

我的未来我决定 提交于 2019-11-26 15:28:59
问题 I am developing an ASP.NET MVC 3 application in C# and I use Razor. I am now dealing with a problem concerning the binding of objects through ViewModels passed/received to/from the View by the Controller. Let's make it clear. I have the following ViewModels: public class ContainerViewModel { public int ContainerId {get; set;} public string ContainerName {get; set;} public List<ItemPostModel> ItemData {get; set;} } public class ItemPostModel { public int ItemId {get; set;} public string

ASP.NET MVC - How exactly to use View Models

Deadly 提交于 2019-11-26 15:19:43
Let's say I have a page that allows the editing of a user's details, so I have a ViewModel like this: public class UserViewModel { public string Username { get; set; } public string Password { get; set; } public int ManagerId { get; set; } public string Category { get; set; } } So on my EditUser action I can have this passed back by the model binder and then I can map that to the Domain Model: public ActionResult EditUser(UserViewModel user) { ... However, the page that displays the form also needs details such as a list of Managers and Categories to provide dropdowns for those fields. It

ASP.NET MVC Model vs ViewModel

别等时光非礼了梦想. 提交于 2019-11-26 15:00:47
OK, I have been hearing discussion about "ViewModels" in regards to MS's ASP.NET MVC. Now, that is intended to be a specific kind of Model, correct? Not a specific kind of View. To my understanding, it's a kind of Model that has a specific purpose of interacting with the View? Or something like that? Some clarification would be appreciated. Essentially Model and View Model are both simple classes with attributes. The main objective of these classes are to describe (to "Model") an object for their respective audiences that are respectively the controller and the view. So you are completely

Why should I use view models?

◇◆丶佛笑我妖孽 提交于 2019-11-26 14:29:27
I'm new to developing web apps using ASP.NET MVC. In fact, I'm rather new to developing web apps, regardless of technology. Currently, I'm working on a project just to get to know the ASP.NET MVC framework better. When reading on SO and elsewhere on the internet, the consensus seems to be that the views should never deal directly with the business objects (i.e. objects implementing business logic and containing associated attributes). Instead, view models should be used. However, this introduces a couple of issues: Where do I put my validation code? I need to add code to map between business