model-binding

How to bind a Knockout js model to a wizard style UI

二次信任 提交于 2019-12-03 11:59:12
I am using Knockout js. I have a view model that contains an array of objects and I want to allow the user to edit one of the objects using a wizard style interface. The issue I have is the wizard will show different steps depending on what choices are made . For instance: If the user selects 'Yes' on step 1 then I display step 2a If the user selects 'No' on step 1 then I display step 2b (ie. a different dialog form) This goes on so that the paths through the wizard are not linear. My question is do I bind all the possible wizard UI steps to the view model at start up even though some steps

What is the equivalent of MVC's DefaultModelBinder in ASP.net Web API?

核能气质少年 提交于 2019-12-03 09:47:05
I want to create a custom model binder in ASP.Net Web API. There are plenty of resources on how to do this from scratch, but I want to leverage existing functionality. I have looked around in the source on codeplex and can see plenty of modelbinders in there but most are sealed... and even then I can't work out which one would be used in which situations. Here is my api method header: public async Task<HttpResponseMessage> Post(long appId, [FromBody]Field field) What I want to do is basically intercept the modelbinder after it has populated all the basic properties, and then set some extra

WebApi2: Custom parameter binding to bind partial parameters

泪湿孤枕 提交于 2019-12-03 07:52:30
问题 I have a webApi2 project and an other project, in which I have my Model classes and a BaseModel that is a base for all Models, as following, public class BaseModel { public string UserId { get; set; } } All the other models are derived from my BaseModel. In webapi I have my CustomerController as following, public class CustomerController : ApiController { [HttpPost] public GetCustomerResponseModel Get(GetCustomerRequestModel requestModel) { var response = new GetCustomerResponseModel(); //I

ModelMetaData, Custom Class Attributes and an indescribable question

扶醉桌前 提交于 2019-12-03 07:36:46
What I want to do seems so simple. In my index.cshtml I want to display the WizardStepAttribute Value So, a user will see at the top of each page, Step 1: Enter User Information I have a ViewModel called WizardViewModel . This ViewModel has a property that is IList<IStepViewModel> Steps each "step" implements the Interface IStepViewModel, which is an empty interface. I have a view called Index.cshtml. This view displays EditorFor() the current step. I have a custom ModelBinder, that binds the View to an new instance of the concrete class implementing IStepViewModel based on the WizardViewModel

Nancy model binding to child class

ぃ、小莉子 提交于 2019-12-03 07:02:33
We are having an issue with Nancy's default model binder. Given the below... public class Foo { public Foo() { } public string Name { get; set; } public Bar Bar { get; set; } } public class Bar { public string Name { get; set; } } with elements like... <input type="text" value="Name" /> <input type="text" value="Bar.Name" /> With the default model binder used like so.. var foo = this.Bind<Foo>(); This correctly binds Foo.Name but fails to bind Foo.Bar.Name Is there a way to enable this kind of binding with the default binder or do we need to roll our own? If so are there any good examples? Why

Percentage properties in MVC 3

那年仲夏 提交于 2019-12-03 06:28:07
My application has many models, many of which contain percentage data. These are represented as decimal or decimal? structs in the model. However, not all properties with decimal structs are percentages. Some should be treated like regular decimals. The percentages need special attention: For display, they should use {0:P2} format. (I have this part working.) For editing, they should allow the same format as the display, i.e. "95" or "95%" or "95.00 %" all bind to a value of 0.95. I started down the road of creating a PercentModelBinder that implements IModelBinder , but then realized that you

How do I use the [Bind(Include=“”)] attribute on complex nested objects?

社会主义新天地 提交于 2019-12-03 05:57:17
问题 I'm creating an inventory of locks, each lock has a serial number (Title), an associated school (SchoolCode), and 5 associated Combinations (having Number, Combination, and IsActive). We're using Ncommon and linq and have set them up as nested entities (Lock Has Many Combinations). On the form, I'm using JQuery Templates to dynamically build the form. Where SchoolCode and Title are basic form elements, Combinations[index].Number and Combinations[index].Combination are the sub-elements. <form

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

HttpPostedFileBase not binding to model

回眸只為那壹抹淺笑 提交于 2019-12-03 05:11:51
here is my ViewModel public class FaultTypeViewModel { [HiddenInput(DisplayValue = false)] public int TypeID { get; set; } [Required(ErrorMessageResourceType = typeof(AdministrationStrings), ErrorMessageResourceName = "FaultTypeNameRequired")] [Display(ResourceType = typeof(AdministrationStrings), Name = "FaultTypeName")] public string TypeName { get; set; } [Display(ResourceType = typeof(AdministrationStrings), Name = "FaultTypeDescription")] [DataType(DataType.MultilineText)] public string TypeDescription { get; set; } [Display(ResourceType = typeof(AdministrationStrings), Name =

Model Binding on Multiple Model Form Submission from Strongly-Typed View

雨燕双飞 提交于 2019-12-03 04:34:54
问题 I'm having problems binding on a form with multiple models being submitted. I have a complaint form which includes complaint info as well as one-to-many complainants. I'm trying to submit the form but I'm getting errors on the bind. ModelState.IsValid always returns false. If I debug and view the ModelState Errors, I get one saying: "The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during