viewmodel

Why can't my view's model bind with my generic ViewModel which implements an interface? (ASP.NET MVC 3)

筅森魡賤 提交于 2019-12-01 17:50:04
I'm trying to pass my View an instance of the following ViewModel: public class CompanyListViewModel<T> where T : ICompany { public IEnumerable<T> CompanyList; public IEnumerable<string> StateList; public CompanyListViewModel(IEnumerable<T> list) { CompanyList = list; } } Where the View takes something like so: @model Project.ViewModels.CompanyViewModels.CompanyListViewModel<ICompany> And my controller code passes something like this to the View: CompanyListViewModel<ICompanyInListAsUser> model = new CompanyListViewModel<ICompanyInListAsUser>(_companyService.FilterByCompanyState(state)); Where

How to use anonymous list as model in an ASP.NET MVC partial view?

随声附和 提交于 2019-12-01 16:43:48
I have a list of Contact objects, from which, I just want a subset of attributes. So I used LINQ projection to create an anonymous list and I passed that to a partial view. But when I use that list in partial view, compiler says that it doesn't have those attributes. I tried the simplest case as follow, but still I have no chance to use an anonymous object or list in a partial view. var model = new { FirstName = "Saeed", LastName = "Neamati" }; return PartialView(model); And inside partial view, I have: <h1>Your name is @Model.FirstName @Model.LastName<h1> But it says that @Model doesn't have

Why can't my view's model bind with my generic ViewModel which implements an interface? (ASP.NET MVC 3)

帅比萌擦擦* 提交于 2019-12-01 16:28:36
问题 I'm trying to pass my View an instance of the following ViewModel: public class CompanyListViewModel<T> where T : ICompany { public IEnumerable<T> CompanyList; public IEnumerable<string> StateList; public CompanyListViewModel(IEnumerable<T> list) { CompanyList = list; } } Where the View takes something like so: @model Project.ViewModels.CompanyViewModels.CompanyListViewModel<ICompany> And my controller code passes something like this to the View: CompanyListViewModel<ICompanyInListAsUser>

MVC View: Type arguments Html helper DisplayFor cannot be inferred from the usage

旧巷老猫 提交于 2019-12-01 16:28:15
问题 I'm trying to make use of the extended HTML Helper DisplayFor in this View: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.SubscriptionsViewModel>" %> <% using (Html.BeginForm("TrainingSubscription", "Account", FormMethod.Post)) { %> <%: Html.DisplayFor(m => m.Subscriptions) %> <input type="submit" value="Save" /> <% } %> with the following ViewModel namespace MvcCms.Web.ViewModels { public class

Model does not apply DataType.Password

淺唱寂寞╮ 提交于 2019-12-01 15:16:51
Instead of using the object directly, on a simple Razor View I have a form using as it+s model a decorator object. public class GlobalAccount { public GlobalAccount() { this.TestService = new TestServiceModel(); } public TestServiceModel TestService { get; set; } } beeing TestServiceModel represented as public class TestServiceModel { [Required] [Display(Name = "Endpoint (url of your service like http://mydomain/remote/)")] public string Endpoint { get; set; } [Required] [Display(Name = "System username")] public string UserName { get; set; } [Required] [DataType(DataType.Password)] [Display

Sunchronizing view model and view

与世无争的帅哥 提交于 2019-12-01 12:44:04
问题 I have a view model that consist of some nodes and some connectors: public class ViewModel { public List<Node> Nodes{get;set;} public List<Connector> Connectors{get;set;} } public Class Node { public Point Position{get;set;} } public class Connector { public Node StartNode{get;set;} public Node EndNode{get;set;} } Now I display nodes in page by an items control: <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Styles.xaml"><

MVVMLight UserControl View Model-Create new Instance of User control for each view

旧街凉风 提交于 2019-12-01 11:57:46
I have a user control of list of Patients which I use in other Views. However when I choose one of the Patients, the selection is propagated to all the views containing an instance of the user control. How can I make each view instantiate a new instance of the user control for each view? I am using c# Guessing from what you stated, I'd assume that you returning a static instance of you PatientViewModel from you locator. To solve this make sure that when the property is called a new instance of the view model is generated. Edit: Locator with different instantiation methods public class

ASP.net MVC - Separate ViewModel for POST Action

本小妞迷上赌 提交于 2019-12-01 09:41:46
In my MVC application I have a View Model that looks similar to this: public class ComplexViewModel { public ComplexDetailsViewModel Details1 { get; set; } public ComplexDetailsViewModel Details2 { get; set; } } public class ComplexDetailsViewModel { public int Id { get; set; } public string DisplayValue1 { get; set; } public string DisplayValue2 { get; set; } // ... } I was originally doing the following in my view: @Html.HiddenFor(model => model.Details1.Id) @Html.HiddenFor(model => model.Details2.Id) @Html.DisplayFor(model => model.Details1.DisplayValue1) ... I would POST the full model to

MvvmCross ViewModel caching and re-initializing

醉酒当歌 提交于 2019-12-01 06:00:47
I need to be able to intercept the framework and perform so re-initialization when a ViewModel is being reloaded from the cache. Since the ViewModel is not being recreated, I can neither use the Init(), MvxViewModel.InitFromBundle, nor MvxViewModel.ReloadFromBundle methods. I am trying to debug a situation where clicking on the back button restores a ViewModel with inconsistent state. Some sort of MvxViewModel.OnReloading() would help. Is there a way to do this in v3? EDIT: Assume I have FirstPageViewModel which exposes a command to navigate to SecondPageViewModel. Based on what I am observing

asp.net MVC should a View-Model Encapsulate Domain-Model?

眉间皱痕 提交于 2019-12-01 05:20:50
I've see a lot of MVC examples where domain-objects are passed directly to views, this will work fine if your view is simple. The common alternative is to have a view-model which has all the same properties as your domain-model + any extra properties your view may need (such as 'confirmPassword'). Before doing too much reading and before discovering AutoMapper I started creating my own variant of view-model where the domain-object (or multiple domain objects) are simply properties of the view-model. Have I done a bad thing? What problems or benefits could be derived from this approach? Under