Why should I use view models?

Where do I put my validation code? On the view models you should validate everything that’s specific to the application like for example the date should be in en-US format culture, …. I need to add code to map between business objects and view models. That’s why there are tools such as AutoMapper. Different problems … Read more

ViewModel with List and editor templates

Assuming you have the following models: public abstract class TableInputModel { } public class RectangleTableInputModel : TableInputModel { public string Foo { get; set; } } public class CircleTableInputModel : TableInputModel { public string Bar { get; set; } } And the following controller: public class HomeController : Controller { public ActionResult Index() { var … Read more

How to bind WPF button to a command in ViewModelBase?

<Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width=”*”/> </Grid.ColumnDefinitions> <Button Command=”{Binding ClickCommand}” Width=”100″ Height=”100″ Content=”wefwfwef”/> </Grid> the code behind for the window: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = new ViewModelBase(); } } The ViewModel: public class ViewModelBase { private ICommand _clickCommand; public ICommand ClickCommand { get { return _clickCommand ?? (_clickCommand … Read more

jquery ui datepicker and mvc view model type datetime

You can look at using the jquery globalize or add the following to your script (assuming of course that the server culture date format is ‘dd/MM/yyy’) $.validator.addMethod(‘date’, function (value, element) { if (this.optional(element)) { return true; } var valid = true; try { $.datepicker.parseDate(‘dd/mm/yy’, value); } catch (err) { valid = false; } return valid; … Read more

What is ViewModel in MVC?

A view model represents the data that you want to display on your view/page, whether it be used for static text or for input values (like textboxes and dropdown lists) that can be added to the database (or edited). It is something different than your domain model. It is a model for the view. Let … Read more