model-binding

ASP.NET Core is using non-default constructor if no public default constructor found

偶尔善良 提交于 2019-12-08 05:11:45
问题 I am writing ASP.NET Core 2.2.0 application hosted on Service Fabric. I have a class which represents a request and I have declared two constructors: public for my own usage and private for serializers: public class MyClass { private MyClass() // for serializer { } public MyClass(string myProperty) // for myself { MyProperty = myProperty ?? throw new ArgumentNullException(nameof(myProperty)); } [Required] public string MyProperty { get; private set; } } Then, I created an API controller:

MVC3 Form binding duplicated across two neighbouring html forms

♀尐吖头ヾ 提交于 2019-12-08 04:18:36
问题 I have a scenario where I have a login form next to a registration form, as the login form is a permanent fixture (until much further development), and sometimes registration as the main content coincides with this login form. Now we enter the twilight zone: Both forms have different actions on different controllers, but they share two things in common, being they both have a ValidationSummary , and they both have a field called UserName . If I cause a server side validation error, e.g. when

ModelBinding parameter list in MVC

丶灬走出姿态 提交于 2019-12-08 03:58:18
问题 I'm trying to use jQuery Datatables 1.10 with server side processing and ASP.NET MVC 5. Unfortunately, Datatables 1.10 writes to the server by serializing a complex hierarchy of objects into a param string ( Content-Type: application/x-www-form-urlencoded ), which breaks the MVC ModelBinder. Is there any way, in MVC, to bind a complex hierarchy of objects passes as a serialized parameter list? Perhaps a custom ModelBinder that someone has written? Note: Setting traditional = true in the ajax

Can I validate HTTP request signature tokens and nonces using Model Binding?

有些话、适合烂在心里 提交于 2019-12-08 02:51:28
问题 I am setting up an end-point using ASP.NET MVC to which requests can be made to manipulate and retrieve data (basically, an API). I am using a 2-legged OAuth model to validate that requests be signed using a secret key and signing method as well as a nonce table to prevent hi-jacking. Since Model Binding is so handy in ASP.NET MVC I am going to take advantage of it to consume requests, but I wonder if I can bake the signature verification and nonce/timestamp handling right into the model

ASP.Net Web API: Formatter Parameter Binding exception

守給你的承諾、 提交于 2019-12-08 01:38:42
问题 I have a DataContract which my Web API action method accepts as an action parameter. public HttpResponseMessage PostMyObject(MyObjectRequestDc objRequest){ ... } [DataContract] public class MyObjectRequestDc { public MyObjectRequestDc() { References = new List<Uri>(); } [DataMember] public List<Uri> References { get; set; } } One of the properties of the contract is a list of URI objects ('References'). If the client ever submits a request which contains a string that does not resolve to a

ASP.net MVC - Use Model Binder without query string values or fancy routes

孤街浪徒 提交于 2019-12-08 00:57:21
问题 I have an Asp.net MVC app that currently works well using the default model binder and urls with complex parameters like this: example.com/Controller/Action?a=hello&b=world&c=1&d=2&e=3 (notice the question mark) The different urls automatically map to Action Method parameters using the built in model binder. I would like to continue using the standard model binder but I need to get rid of the query string. We want to put these urls behind a CDN that does not support resources that vary by

Question about JSON and Serialization

 ̄綄美尐妖づ 提交于 2019-12-07 22:34:39
问题 I have a strongly typed view with my viewmodel which contains an object Person and an List of Skills. Person is quite straightforward. I use Html Helpers like this @Html.TextBoxFor(m => m.Person.FirstName) . I submit my form and get what I want. The problem is my List of skills. With an AJAX call i get a JSON result which is an array of Skills. How should I send the combination of both the skills and the person to my HTTPPOST method? I see two possibilities. The one I favour, but have no idea

Custom model binding on derived property not working

房东的猫 提交于 2019-12-07 19:06:01
问题 I have a custom ModelBinder (MVC3) that isn't getting fired for some reason. Here are the relevant pieces of code: View @model WebApp.Models.InfoModel @using Html.BeginForm() { @Html.EditorFor(m => m.Truck) } EditorTemplate @model WebApp.Models.TruckModel @Html.EditorFor(m => m.CabSize) ModelBinder public class TruckModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { throw new NotImplementedException(); } } Global

ASP.NET MVC Updating a list of objects on one form? (model binding to a list)

血红的双手。 提交于 2019-12-07 18:23:45
问题 Quick question regarding updating a list of items in asp.net mvc. Basically I have an edit action method that returns a collection of objects (incidentally, the table structure of which looks as follows 'testID, assetID, Result' - a link table). I basically want this items to be displayed one after another in a form and to be able to edit them. The form should post back and the modelbinder do its magic. But, its not that easy. I have scoured the net and it seems the majority of the

MVC3 Form binding duplicated across two neighbouring html forms

蓝咒 提交于 2019-12-07 18:13:28
I have a scenario where I have a login form next to a registration form, as the login form is a permanent fixture (until much further development), and sometimes registration as the main content coincides with this login form. Now we enter the twilight zone: Both forms have different actions on different controllers, but they share two things in common, being they both have a ValidationSummary , and they both have a field called UserName . If I cause a server side validation error, e.g. when the user hasn't ticked 'Accept terms of use', using ModelState.AddModelError("", "You must accept the