updatemodel

How to update Model when binding to a ViewModel?

◇◆丶佛笑我妖孽 提交于 2019-12-03 05:57:15
问题 I have an [HttpPost] action method signature like this: [HttpPost] public ActionResult Edit(ExistingPostViewModel model) { // Save the edited Post. } Now, in the past (when i didn't use ViewModels, e.g R&D), i had an implementation of an Edit method like this: [HttpPost] public ActionResult Edit(Post model) { var existingPost = repo.Find(model.Id); TryUpdateModel(existingPost); repo.Save(existingPost); return RedirectToAction("Success", existingPost.Id); } Which worked great. But i'm confused

ASP.NET MVC UpdateModel with a sorta complex data entry field

半腔热情 提交于 2019-11-30 11:28:16
问题 how do i do the following, with an ASP.NET MVC UpdateModel? I'm trying to read in a space delimeted textbox data (exactly like the TAGS textbox in a new StackOverflow question, such as this) into the model. eg. <input type="Tags" type="text" id="Tags" name="Tags"/> ... public class Question { public string Title { get; set; } public string Body { get; set; } public LazyList<string> Tags { get; set; } } .... var question = new Question(); this.UpdateModel(question, new [] { "Title", "Body",

ClassCastException when calling TreeSet<Long>.contains( Long.valueOf( someLongValue ) )

假装没事ソ 提交于 2019-11-30 06:05:11
问题 Im stumped. I declare my set thusly: private Set<Long> applicationIds; Then I populate it like this: public void setApplicationIds( Set<Long> applicationIds ) { this.applicationIds = new TreeSet<Long>( applicationIds ); this.applications = null; } Then I attempt to use it: public List<Application> getApplications() { if ( applications == null ) { applications = new ArrayList<Application>(); if ( applicationIds != null ) { for ( Application application : availableApplications ) { if (

What is correct behaviour of UpdateModel in ASP.NET MVC?

你。 提交于 2019-11-29 23:10:11
I am interested to know what you guys feel should be deemed "correct behaviour" in terms of the UpdateModel method in ASP.NET MVC. The reason I ask here is perhaps if this functionality is "by design" somebody could clarify as to why it is the way it is, and perhaps a way to call it differently to achieve desired functionality, which I would imagine would be the way 90% of folk would want this to work? In essence, my gripe lies with the behaviour of the binding process within UpdateModel . Supposing you wish to update a form via a simple Save action method for which the data fields on the form

Cascading p:selectOneMenu model value not set

China☆狼群 提交于 2019-11-29 12:51:37
i have an application where i have a cascading dropdown, a simple dropdown and a submit commandButton. i wish to show report in datatable by selecting various criteria from the dropdowns. all works fine except when i wish to select the criteria from child dropdown. it doesnt bind with its value in the managed bean(found that by debugging). here's my code: xhtml: <h:outputText value="Exchange"/> <p:selectOneMenu style="width: 150px" value="#{reportBean.exchange}"> <f:selectItem itemLabel="--select--" itemValue="--select--"/> <f:selectItem itemLabel="NSE" itemValue="nse"/> <f:selectItem

Is the Rails update_attributes method the best choice for doing an update of a model in the database?

感情迁移 提交于 2019-11-28 21:22:24
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails 1.1.6 tutorial that I'm covering recommends using the update_attributes method for updating a model, as in the example code from my controller listed above. Looking at the Rails documentation I'm wondering why the update method would not have been preferred, especially since it is named so logically. Update takes an object id parameter and a set of attributes that otherwise work like update_attributes . So this (from AWDWR 3rd edition

ClassCastException when calling TreeSet<Long>.contains( Long.valueOf( someLongValue ) )

烂漫一生 提交于 2019-11-28 14:42:30
Im stumped. I declare my set thusly: private Set<Long> applicationIds; Then I populate it like this: public void setApplicationIds( Set<Long> applicationIds ) { this.applicationIds = new TreeSet<Long>( applicationIds ); this.applications = null; } Then I attempt to use it: public List<Application> getApplications() { if ( applications == null ) { applications = new ArrayList<Application>(); if ( applicationIds != null ) { for ( Application application : availableApplications ) { if ( applicationIds.contains( Long.valueOf( application.getId() ) ) ) { applications.add( application ); } } } }

Update existing database with Entity Framework Code First in MVC

早过忘川 提交于 2019-11-28 08:40:08
In my MVC application I used Entity Framework 6 and created database with code first approach. After a certain time, I updated one of the entity classes by adding new column and removing some columns. For reflecting these changes to the database I followed the steps below: Deleted the migrations folder in the project. Deleted the __MigrationHistory table in the database. Then run the following command in the Package Manager Console: Enable-Migrations -EnableAutomaticMigrations -Force Add the following lines in configuration file: AutomaticMigrationsEnabled = true;

Cascading p:selectOneMenu model value not set

旧时模样 提交于 2019-11-28 06:11:36
问题 i have an application where i have a cascading dropdown, a simple dropdown and a submit commandButton. i wish to show report in datatable by selecting various criteria from the dropdowns. all works fine except when i wish to select the criteria from child dropdown. it doesnt bind with its value in the managed bean(found that by debugging). here's my code: xhtml: <h:outputText value="Exchange"/> <p:selectOneMenu style="width: 150px" value="#{reportBean.exchange}"> <f:selectItem itemLabel="-

How do I Unit Test Actions without Mocking that use UpdateModel?

人盡茶涼 提交于 2019-11-27 16:29:49
问题 I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC Beta 1. In it he shows the improvements made to the UpdateModel method and how they improve unit testing. I have recreated a similar project however anytime I run a UnitTest that contains a call to UpdateModel I receive an ArgumentNullException naming the controllerContext parameter. Here's the relevant bits, starting with my model: public class Country { public Int32 ID { get; set; } public String Name { get;