viewmodel

MVC Custom ViewModel and auto binding

岁酱吖の 提交于 2019-12-09 04:46:48
问题 I have a custom ViewModel defined as : public class SampleFormViewModel { public SampleFormViewModel(SelectList companies, Widget widget) { Companies = companies; Widget = widget; } public SelectList Companies { get; private set; } public Widget Widget { get; private set; } } In my Edit POST handler I have the following entry: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(SampleFormViewModel model) { Edit form is set up as: Inherits="System.Web.Mvc.ViewPage<Sample.Web.Models

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

丶灬走出姿态 提交于 2019-12-09 03:29:26
问题 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

Knockout view model posts back to ASP.NET MVC partially - how to post back complete object?

前提是你 提交于 2019-12-09 03:16:27
Having these ASP.NET MVC view models: public class User { public string Name { get; set; } public LabeledEmail LabeledEmail { get; set; } } public class LabeledEmail { public IList<ContactLabel> Labels; public IList<ContactEmail> Emails; } and Knockout view model like this: <script type="text/javascript"> $(function() { ko.applyBindings(viewModel); $("#profileEditorForm").validate({ submitHandler: function(form) { if (viewModel.save()) window.location.href = "/"; return false; } }); }); var viewModel = { Name: ko.observable("@Model.Name"), EmailLabels: ko.observableArray(@Html.Json(Model

Using ViewModels instead DTOs as the result of a CQRS query

戏子无情 提交于 2019-12-08 19:16:31
问题 Reading a SO question, I realized that my Read services could provide some smarter object like ViewModels instead plain DTOs. This makes me reconsider what information should be provided by the objects returned by the Read Services Before, using just DTOs, my Read Service just made flat view mapping of a database query into hash like structure with minimum normalization and no behavior. However I tend to think of a ViewModel as something "smarter" that can have generated information not

MVC generic ViewModel

百般思念 提交于 2019-12-08 16:33:41
问题 In short I would like to be able to pass a generic ViewModel into my views Here is some simplified code of the gist of what I am trying to achieve public interface IPerson { string FirstName {get;} string LastName {get;} } public class FakePerson : IPerson { public FakePerson() { FirstName = "Foo"; LastName = "Bar"; } public string FirstName {get; private set;} public string LastName {get; private set;} } public class HomeViewModel<T> where T : IPerson, new() { public string SomeOtherProperty

MVC map to nullable bool in model

社会主义新天地 提交于 2019-12-08 15:04:50
问题 With a view model containing the field: public bool? IsDefault { get; set; } I get an error when trying to map in the view: <%= Html.CheckBoxFor(model => model.IsDefault) %> Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) I've tried casting, and using .Value and neither worked. Note the behaviour I would like is that submitting the form should set IsDefault in the model to true or false. A value of null simply means that the model has

“Specified argument was out of the range of valid values.Parameter name: index” when adding new item to ObservableCollection<T>

左心房为你撑大大i 提交于 2019-12-08 13:00:04
问题 I get a such exception: 'FooStorageStorage.Add(new TreeViewItem() { Header=i.ToString()})' threw an exception of type 'System.ArgumentOutOfRangeException': "Specified argument was out of the range of valid values.\r\nParameter name: index" I have a property in viewModel: private ObservableCollection<TreeViewItem> fooStorage=new ObservableCollection<TreeViewItem>(); public ObservableCollection<TreeViewItem> FooStorage { get { return facetStorage; } set { facetStorage = value; } } However,

How to get a ViewModel?

旧时模样 提交于 2019-12-08 11:52:26
问题 I just want to get a reference in my Fragment (extends Fragment) to my ViewModel.class (extends from AndroidViewModel). This is how it is described everywhere: UserModel userModel = ViewModelProviders.of(getActivity()).get(UserModel.class); description on Android Developer ..., but ViewModelProviders is deprecated since long ago. *This class was deprecated in API level 1.1.0. * I can't import the class with: android.arch.lifecycle.[ViewModelProviders] it just offers ViewModelProvider and

post viewmodel with IList to controller post method

爱⌒轻易说出口 提交于 2019-12-08 11:48:34
问题 I have a view model with a IList: public class MyMaintenanceListViewModel { public IList<MyMaintenance> MyMaintenanceList { get; set; } [Display(Name = "Network User Name:")] public string NetworkUserName { get; set; } [Display(Name = "Password:")] public string Password { get; set; } } I have a view whose model is set to the viewmodel: @model EMMS.ViewModels.MyMaintenanceListViewModel @using (Html.BeginForm("SubmitMaintenance", "Maintenance")) { <table id="searchtable" class="MyMaintenance">

Who should create view model instances in MvvmCross

▼魔方 西西 提交于 2019-12-08 08:52:22
问题 Just to make it clear: I know MvvmCross is very flexible about where and how view models can be created. My question is more about proper separation of concerns, to simplify design of complex cross-platform applications. Consider we have an app with customer list and customer details. On iPad and Surface the list and details are shown on the same page, but on smaller devices customer list and details for a selected customer are split between separate pages. So we have a PCL with