asp.net-mvc-viewmodel

Bind DropDownListFor with List on ViewModel

青春壹個敷衍的年華 提交于 2019-12-10 22:55:14
问题 I'm trying to do this: This is my ViewModel and Model: public class OpeningYearViewModel { public int OpeningYearId { get; set; } public string Description { get; set; } public List<Grade> GradesList { get; set; } } public class Grade { public int GradeId { get; set; } public string Name { get; set; } public int CurrencyId { get; set; } public int Cost { get; set; } } This is my Controller. I build a SelecList here and pass it to the view through the ViewBag OpeningYearViewModel viewmodel =

MVC View ViewModel HttpPost return value is always NULL

徘徊边缘 提交于 2019-12-10 04:33:49
问题 I'm passing a ViewModel back from my View to the Controller via a form HttpPost. However, the values returned are always NULL. ViewModel public class vmCompanyAddress { public StatelyTechAdmin.Models.Company Company { get; set; } public StatelyTechAdmin.Models.CompanyAddress Address { get; set; } public SelectList Counties { get; set; } } Company Class Model public class Company { [Key] public virtual long CompanyId { get; set; } [Required] [Display(Name = "Company Name")] public virtual

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

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

Creating a ViewModel from two EF Models in ASP.Net MVC5

余生颓废 提交于 2019-12-08 03:24:18
问题 I have been searching around and really can not find a decent answer on how to build a ViewModel and then fill that with the data from my EF model. The two EF models I want to push into a single ViewModel are: public class Section { [DatabaseGenerated(DatabaseGeneratedOption.Identity), HiddenInput] public Int16 ID { get; set; } [HiddenInput] public Int64? LogoFileID { get; set; } [Required, MaxLength(250), Column(TypeName = "varchar"), DisplayName("Route Name")] public string RouteName { get;

How do I pass an ID from View to the ViewModel as a parameter for GET function?

我的未来我决定 提交于 2019-12-07 19:36:25
问题 I'm creating a project using MVC, knockoutJS, Web API, Bootstrap and so forth, the database in use is MSSQL Server 2012. It's all working very well, the controllers have properly created CRUD operations. The data from DB is show in a grid table in the UI, and every row is clickable, and opens up a modal in which the data about that exact element is shown. The problem I'm experiencing is the inability to pass a certain value of the row, in this case an ID, to ViewModel as a parameter for

Having to repopulate viewmodel when modelstate is invalid due to not sending all data in such as drop down box list

自古美人都是妖i 提交于 2019-12-07 08:25:15
问题 In my project I create a survey, I link this survey to a company and select users to participate. I select survey template, add extra questions and sets information about the survey such as start and end date. All in all the result is a complex view with data from many parts of the domain. I created a ViewModel for this view that would include things such as a list for all companies (because i need to select company in a drop down list). Now the annoyance is that when i submit to save, if i

Creating a ViewModel from two EF Models in ASP.Net MVC5

人盡茶涼 提交于 2019-12-06 11:34:26
I have been searching around and really can not find a decent answer on how to build a ViewModel and then fill that with the data from my EF model. The two EF models I want to push into a single ViewModel are: public class Section { [DatabaseGenerated(DatabaseGeneratedOption.Identity), HiddenInput] public Int16 ID { get; set; } [HiddenInput] public Int64? LogoFileID { get; set; } [Required, MaxLength(250), Column(TypeName = "varchar"), DisplayName("Route Name")] public string RouteName { get; set; } [Required, MaxLength(15), Column(TypeName = "varchar")] public string Type { get; set; }

Having to repopulate viewmodel when modelstate is invalid due to not sending all data in such as drop down box list

半腔热情 提交于 2019-12-05 15:39:49
In my project I create a survey, I link this survey to a company and select users to participate. I select survey template, add extra questions and sets information about the survey such as start and end date. All in all the result is a complex view with data from many parts of the domain. I created a ViewModel for this view that would include things such as a list for all companies (because i need to select company in a drop down list). Now the annoyance is that when i submit to save, if i have a modelstate error then i want to redisplay the view but since all the data i fetched such as list

MVC View ViewModel HttpPost return value is always NULL

筅森魡賤 提交于 2019-12-05 07:59:07
I'm passing a ViewModel back from my View to the Controller via a form HttpPost. However, the values returned are always NULL. ViewModel public class vmCompanyAddress { public StatelyTechAdmin.Models.Company Company { get; set; } public StatelyTechAdmin.Models.CompanyAddress Address { get; set; } public SelectList Counties { get; set; } } Company Class Model public class Company { [Key] public virtual long CompanyId { get; set; } [Required] [Display(Name = "Company Name")] public virtual string Name { get; set; } public virtual DateTime CreatedDate { get; set; } public virtual IEnumerable