viewmodel

Is the ViewModel in asp.net comparable to the ViewModel in WPF

给你一囗甜甜゛ 提交于 2019-12-08 02:31:16
问题 If you know the MVVM pattern for WPF then you know Josh smith msdn article where a CustomerViewModel does not hold a simple property like: public string FirstName {get;set;} Rather a ViewModel wraps a Model and delegates the property access like this: public string FirstName { get { return _customer.FirstName; } set { if (value == _customer.FirstName) return; _customer.FirstName = value; base.OnPropertyChanged("FirstName"); } } I have not seen this in asp.net mvc. Is this due to the missing

How to let the post action method take a subobject of the original viewmodel as a parameter?

*爱你&永不变心* 提交于 2019-12-08 02:25:34
问题 This is my model: public class IndexViewModel { public FilterConditions conditions { get; set } public IEnumerable<SelectListItem> Countries { get; set } } public class FilterConditions { public string condition11 { get; set } // ... } And I have an Index action method like so: public ActionResult Index() { var model = new IndexViewModel(); // fill the model here with default values return View(model); } The view renders a form with the filterconditions as input types. Now I want the post

How do i design a composite view and view model using Silverlight and MVVM?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 01:32:00
问题 I want to create a "Wizard" in my Silverlight MVVM application. The Wizard should contain multiple steps between which you can navigate using "next" and "previous". The problem I am facing is the relationship between views and view models. I want there to be a view and view model for the Wizard itself. My instinct tells me that there should be one view/view model pair for each step in the wizard. What is a good approach for maintaining these kinds of relationships, where one view model holds

Is it possible to pass a partial view a different model than the model used by the view it is in?

↘锁芯ラ 提交于 2019-12-08 01:04:03
问题 I tried to do it but I get an error saying that model x was expected but y was passed in. 回答1: Yes. In fact you can use any class, but it has to match the @model declaration of your partial view. Partial View: @model partialViewModel <h2>@Model.partialViewModelProperty</h2> Main View: @model mainViewModel <h1>Model.mainViewModelProperty</h1> @Html.Partial("_PartialView", new partialViewModel() { partialViewModelProperty = "A title" }) 回答2: No, that is the point of a strongly-typed View. It

ASP.net MVC - Separate ViewModel for POST Action

孤者浪人 提交于 2019-12-07 16:16:57
问题 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

MVC3 passing base class to partial View - submitting form only has parent class values

耗尽温柔 提交于 2019-12-07 16:03:41
问题 I have a number of child ViewModel classes which inherit from an base ViewModel class. I pass my child ViewModel into my View, which then passes itself into a partial view. The main view takes the child type, but the partial view takes the Parent type. Everything displays correctly when I manually populate the properties. However, when I Submit the form, my controller action only has properties for the Child class - none of the base class properties are completed? e.g. public abstract class

Patterns for mapping data between domain models

限于喜欢 提交于 2019-12-07 13:58:04
问题 This is a common thing that I have been needing to do recently and I was looking for any common patterns to make this a little easier. The main gist of it all is that I have some data models, which are modelled to satisfy the ORM and purely do CRUD operations to objects. These models are currently exposed via repositories/factories (dependant upon if its C or RUD). I then have a view model, which is a bit more readable, and is sprinkled with UI concerns, such as validation and mapping data

.net mvc razor dropdowns for foreign keys

我的梦境 提交于 2019-12-07 13:42:31
Ok, this seemed simple, but is making my head spin. I have created models based on CodeFirst. public class Category { public int ID { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } public class SubCategory { public int ID { get; set; } public Category category { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } Now when i auto-generate the controller and view for SubCategory it (out-of-the-box) lets me create new SubCategory objects without specifying the Category (even through it correctly creates a foreign key

Validating Nested Models

泄露秘密 提交于 2019-12-07 05:39:00
问题 I currently have a ViewModel setup as such: public class OurViewModel { public OurViewModel() { } [Required] public int LeadID { get; set; } [Required] public int Rate { get; set; } [Required] public bool DepositRequired { get; set; } [RequiredIfOtherPropertyIsTrue("DepositRequired")] public BankInfo { get; set; } } ...in this case, "RequiredIfOtherPropertyIsTrue" is a validator that does pretty much what it says: checks to see if another property is true (in this case, our boolean indicating

Accessing ViewModel in JS file (asp.net MVC)

ε祈祈猫儿з 提交于 2019-12-07 04:20:16
问题 I have been using something like this inside Razor @section Includes { <script type="text/javascript"> var somestuffneeded = @(Html.Raw(Json.Encode(Model.datamember))); </script> } But this looks not so clean because it goes in the same file as the layout, (since it won't work from the .js file directly). Any clean alternatives to accessing and viewing the ViewModel passed inside .js file? 回答1: You can't directly access ViewModel in .js file because its static file on your web server. But