viewmodel

ASP MVC 3 Two Models in One View

倖福魔咒の 提交于 2019-12-08 07:34:06
问题 I am working on creating a datagrid in ASP MVC 3 where I have two tables in one view. Each table is being used from its own Model. Therefore, I would have to call two Models into one View which does not seem as simple as I wish it was. I am pretty new to MVC and I was looking through Stack and found this link: Two models in one view in ASP MVC 3 Which seems to be the direction that i would want to go... I think. Here is the code for my first model: [Table] public class Model1 { [Column

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

早过忘川 提交于 2019-12-08 05:57:37
问题 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

How to post the selected value of a selectlist to the controller using a view model?

时光毁灭记忆、已成空白 提交于 2019-12-08 05:27:06
问题 This question has been asked in various forms but none of the answers seem to fit my situation. I am simply trying to retrieve the selected value of a dropdown list in my controller. Here is my code: ViewModel.cs public class ViewModel { public ViewModel() {} public ViewModel(Contact contact, IEnumerable<State> states) { this.Contact = contact; this.States = new SelectList(states, "Id", "Name", contact.StateId); } public Contact Contact {get;set;} public SelectList States {get;set;} }

Should AutoMapper also be used as a Re-Shape mapping tool

泪湿孤枕 提交于 2019-12-08 05:06:37
问题 I know AutoMapper is just to map properties between 2 objects. Automapper is not for reshaping data this must be programmed in my opinion. I have a PeriodDTO.IEnumerable<Period> which needs to be reshaped into a PeriodListViewModel.List<CellViewModel> . Each CellViewModel holds a List<RowViewModel> This is no 1 to 1 mapping not and I guess maybe this should not be mapped - because its not possible - public class PeriodRequest { public IEnumerable<Period> Periods { get; set; } public

.net mvc razor dropdowns for foreign keys

丶灬走出姿态 提交于 2019-12-08 04:48:35
问题 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

Why do I still need business models in asp.net mvc when a viewmodel does all the input validation?

别说谁变了你拦得住时间么 提交于 2019-12-08 04:28:33
问题 This is not a viewmodel vs model question! this could be a typical viewmodel`s property: [Required] [StringLength(6, MinimumLength = 3)] [Remote("IsUID_Available", "Validation")] [RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed.")] [Editable(true)] public String UserName {get;set;} For what then do I still need my model except for transporting the data to my data access layer? Then its not a business model. Its a Data Access Object: http://en.wikipedia.org/wiki/Data

Why is this View not correctly binding to this ViewModel?

醉酒当歌 提交于 2019-12-08 03:49:33
问题 I'm trying to bind my view to my view model without DataObjectProvider. The following code runs without an error , but my ListBox is empty . As far as I can tell, I correctly: set the View's DataContext to the ViewModel itself ( DataContext = new CustomersViewModel(); ) expose the customer objects in the ViewModel ( public static ObservableCollection<Customer> GetAll() ) bind the ListBox to the customer objects ( ItemsSource="{Binding GetAll}" ) What little piece of syntax am I missing here?

ViewModel location when doing CQRS

前提是你 提交于 2019-12-08 03:13:50
问题 Suppose you have a layered project divided into the Presentation Layer, the Business Layer and the Data Access Layer. If you were using CQRS, you would be doing queries directly from the Data Access Layer into the Presentation Layer and bypassing the Business Layer. In that case, if you are using ViewModels in your presentation layer, then your Data Access Layer would need reference to the Presentation Layer to return data in terms of the ViewModels in the presentation layer. Wouldn't that be

What is the appropriate granularity in building a ViewModel?

☆樱花仙子☆ 提交于 2019-12-08 03:04:19
问题 I am working on a new project, and, after seeing some of the difficulties of previous projects that didn't provide enough separation of view from their models (specifically using MVC - the models and views began to bleed into each other a bit), I wanted to use MVVM. I understand the basic concept, and I'm excited to start using it. However, one thing that escapes me a bit - what data should be contained in the ViewModel? For example, if I am creating a ViewModel that will encompass two pieces

How do I view the parent view model MVC3 C#?

旧城冷巷雨未停 提交于 2019-12-08 02:41:32
问题 I want to use two models in one view and have looked at parent view model. I have two models: public class Blogg { public int ID { get; set; } public string Blogg_name { get; set; } public string Message { get; set; } public string Blogg_subject { get; set; } private DateTime _Blogg_date = DateTime.Now; public DateTime Blogg_date { get { return _Blogg_date; } set { _Blogg_date = value; } } } And public class Dish { public int ID { get; set; } public string Title { get; set; } public string