model-binding

ASP.NET Core Posting Array Object JSON

假装没事ソ 提交于 2019-12-10 02:29:13
问题 I'm trying to post an array of Object in my view to my controller but params are null i saw that for just a simple object I need to put [FromBody] in my controller action. Here is my JSON: { "monJour": [ { "openTime": "04:00", "closedTime": "21:30", "id": "0" }, { "openTime": "08:00", "closedTime": "17:30", "id": "1" }, { "openTime": "08:00", "closedTime": "17:30", "id": "2" }, { "openTime": "08:00", "closedTime": "17:30", "id": "3" }, { "openTime": "08:00", "closedTime": "17:30", "id": "4" }

Customize mapping request parameters and fields inside the DTO ?

无人久伴 提交于 2019-12-10 01:52:33
问题 I have the following class: public class MyDTO { private String kiosk; ... } and following url: http://localhost:1234/mvc/controllerUrl?kiosk=false and following controller method: @RequestMapping(method = RequestMethod.GET, produces = APPLICATION_JSON) @ResponseBody public ResponseEntity<List<?>> getRequestSupportKludge(final MyDTO myDTO, BindingResult bindingResult) { ... } Now it is working nice and boolean field resolves properly. Now url parameter has changed like this: http://localhost

MVC.Net binding complex models?

守給你的承諾、 提交于 2019-12-10 00:03:22
问题 I have the following code, with an existing customer. I need to create a form that created an Order, and pass it to my Controller. I tried changing my model type on that page to Order instead of Customer, but then I'm gonna have to pass the Order object as well, or at least the OrderId. Models public class Customer { public int Id { set; get; } public string FirstName { set; get; } public string LastName { set; get; } public List<Order> Orders { get; set;} } public class Order { public int Id

asp.net mvc checkbox/radiobutton matrix model-binding

半世苍凉 提交于 2019-12-09 23:35:27
问题 I have a dynamic forms with checkbox/radio-button lists & matrices: Following code renders checkbox list: @foreach (var sq in Model.SubQuestions) { <label> <input type="hidden" name="answerResult.index" value="@sq.Id" /> <input type="checkbox" name="answerResult[@sq.Id].SubQuestionId" value="@sq.Id" /> @sq.Label.Name </label> } radio-button list: <input type="hidden" name="answerResult.index" value="@Model.Id" /> @foreach (var sq in Model.SubQuestions) { <label> <input type="radio" name=

Gwt editor with not only getter/setter bean class

纵然是瞬间 提交于 2019-12-09 21:30:05
问题 Lets say I have form build in GWT, an UI-Binder, which implements Editor interface (com.google.gwt.editor.client.Editor) with two date fields (date from and to). Bean class is expected to have members: Date fromDate; // with getter and setter Date toDate; // with getter and setter And okay, while having bean class defined as written, there is no problem, but just after I add something like this: public boolean hasFromDate() { return fromDate != null; } I got compilation error (for example for

DataContract model binding to JSON in ASP.NET MVC Action Method Arguments

我的未来我决定 提交于 2019-12-09 17:34:56
问题 MVC3 comes out of the box with JsonValueProviderFactory() which is very handy for binding incoming JSON to a model. Unfortunately, I can't figure out how to setup model contracts with names that differ from the incoming JSON. For example: [DataContract(Name = "session")] public class FacebookSession { [DataMember(Name = "access_token")] public string AccessToken { get; set; } [DataMember(Name = "expires")] public int? Expires { get; set; } [DataMember(Name = "secret")] public string Secret {

Using [FromUri] attribute - bind complex object with nested array

大兔子大兔子 提交于 2019-12-09 16:11:38
问题 I want to send a complex object with a nested array in the uri to an MVC action method in a GET request. Consider the following code: public ActionResult AutoCompleteHandler([FromUri]PartsQuery partsQuery){ ... } public class PartsQuery { public Part[] Parts {get; set; } public string LastKey { get; set; } public string Term { get; set; } } $.ajax({ url: "Controller/AutoCompleteHandler", data: $.param({ Parts: [{ hasLabel: "label", hasType: "type", hasIndex : 1 }], LastKey : "Last Key", Term

Late binding Dynamically Resolve Models after entering controller

对着背影说爱祢 提交于 2019-12-09 15:42:18
问题 I'm looking for a way to resolve a model after entering into an action in a controller , the simplest way to describe the problem would be: public DTO[] Get(string filterName) { //How can I do this this.Resolve<MyCustomType>("MyParamName"); } If you're looking for more information on why I'm trying to do that you can continue reading to get the full picture TL;DR I'm looking for a way to resolve a model a request, given a parameter name that will always be resolved from query string How can I

.NET Model Binders

被刻印的时光 ゝ 提交于 2019-12-09 14:58:11
问题 I was trying to create custom model binder in my ASP.NET MVC 4 project. But i get stuck with IModelBinder iterfaces. There are three IModelBinder interfaces VS can find. In following namespaces. using System.Web.Http.ModelBinding; using System.Web.Mvc; using System.Web.ModelBinding; bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext); bool BindModel

Backbone.js: avoid view→model→view double conversion

随声附和 提交于 2019-12-09 10:30:48
问题 I’m trying to build this: When I edit field on the left it should update the one on the right and vice-versa. Editing a value in an input field causes the text cursor to jump at the end of it. Typing "2" in the fahrenheit field gets replaced with 1.999999999999, as you can see on the screenshot. This happens because of the double conversion: view’s Fº → model’s Cº → view’s Fº. How can I avoid that? Update: I want to know the elegant way of dealing with two-way bindings in MVC frameworks such