model-binding

ASP.NET Core MVC - Model Binding : Bind an interface model using the attribute [FromBody] (BodyModelBinder)

陌路散爱 提交于 2019-12-07 17:33:42
问题 I want to bind an interface model from my action method with a request that the content-type is application/json. I'm using the [FromBody] attribute in my action method. I tried to create a custom modelBinder derived from ComplexTypeModelBinder, by following this link: Custom Model Binding in Asp.net Core, 3: Model Binding Interfaces, but it doesn't work, my model is always null. I learned after that when you use the atribute [FromBody] the BodyModelBinder is called and internally is calling

Angular two-way-binding with sub elements

折月煮酒 提交于 2019-12-07 16:31:28
问题 my problem is with creating an angular directive. I want to create a group of checkboxes with just one single ng-model. It's like a bitfield or flags, i.e. the checkboxes have values from 0, 1, 2, 3 up to n but for ng-model I just want to add 2^value of all checked checkboxes. The values to add are then 1, 2, 4, 8, 16, ... I wonder if there is a better, more correct or just simpler solution to my problem. http://plnkr.co/edit/9h7EkEpDohXTniIDHdc5 In the example you can change the value in the

Upload multiple files in MVC3 with model binding

夙愿已清 提交于 2019-12-07 15:11:17
问题 So I want to catalogue my record collection. I also want to learn some MVC. So I decided to build a record cataloguing website in MVC. That's how I work. I'm just dipping my toes in but cannot figure out how to upload multiple files to my SQLCE database. I'm open to options here - store the images as BLOBS or simply as filenames and upload the images to the filesystem. My simple model is this: public class Record { [ScaffoldColumn(false)] public int RecordId { get; set; } [Required

MVC Nested model binding only partially working - what am I missing?

南楼画角 提交于 2019-12-07 12:05:29
问题 I have a ViewModel called AssetSearchModel with a property of type: List. When I post from the ViewModel, all the properties of my List get binded back to the model successfully, except for this one: public DomainsDto DomainControl { get; set; } which is defined at the bottom. That domaincontrol has a couple of properties and then its own nested list... none of its properties get set, they are all null public class AssetSearchModel { public List<SearchControlModel> SearchControls { get; set;

Custom DateTime model binder in ASP.NET Core 1 (RTM)

流过昼夜 提交于 2019-12-07 11:30:00
问题 I'm writing and ASP.NET Core 1 application, which has a Web API Controller where supplier will post data. This is a simplified version of the Model class to which I will bind the incoming data: public class Lead { public int SupplierId { get; set; } public DateTime Date { get; set; } } The problem is that the dates will be posted with German formatting, for instance, 30.09.2016 . I do not want to set the global culture of the application to de-DE because a) I'm not German, and b) the rest of

Querystring Model Binding ASP.NET WebApi

醉酒当歌 提交于 2019-12-07 10:10:52
问题 I have the following model public class Dog { public string NickName { get; set; } public int Color { get; set; } } and I have the following api controller method which is exposed through an API public class DogController : ApiController { // GET /v1/dogs public IEnumerable<string> Get([FromUri] Dog dog) { ...} Now, I would like to issue the GET request as follows: GET http://localhost:90000/v1/dogs?nick_name=Fido&color=1 Question: How do I bind the query string parameter nick_name to

asp.net web api - model binding list parameter

最后都变了- 提交于 2019-12-07 09:25:01
问题 In my controller I have: [AcceptVerbs("GET", "POST")] public List<BuzzMonitor.Web.Message> Search(string text, DateTime dateFrom, DateTime dateTo, List<int> themeIds, List<int> sourceIds) {...} and I want to do model binding. It's easy for primitive types, but what to do when I have a list of primitive types? I did it like this in Global.asax: GlobalConfiguration.Configuration.Routes.MapHttpRoute("SearchWithParameters", "api/{controller}/{action}/{text}/{dateFrom}/{dateTo}/?/?" But I dont

Validating Nested Models

泄露秘密 提交于 2019-12-07 05:39:00
问题 I currently have a ViewModel setup as such: public class OurViewModel { public OurViewModel() { } [Required] public int LeadID { get; set; } [Required] public int Rate { get; set; } [Required] public bool DepositRequired { get; set; } [RequiredIfOtherPropertyIsTrue("DepositRequired")] public BankInfo { get; set; } } ...in this case, "RequiredIfOtherPropertyIsTrue" is a validator that does pretty much what it says: checks to see if another property is true (in this case, our boolean indicating

Model binding a list of checkboxes problem

折月煮酒 提交于 2019-12-07 04:49:46
问题 In my EditorTemplates, i Have two Views. One for my Category (called _Category) @model com.example.Models._Category @Html.CheckBox(Model.Name, Model.Selected) @Html.LabelFor(c => c.Name, Model.Name) <br /> and one for the List of Categories (called _Categories) @model List<com.example.Models._Category> @for (int i = 0; i < Model.Count; i++) { @Html.EditorFor(c => Model[i]); } In the view that shows these categories, i have a list of Categories which is being used like so: @Html.EditorFor(m =>

Using Required and JsonRequired in ASP.NET Core Model Binding with JSON body

最后都变了- 提交于 2019-12-07 04:26:20
问题 I'm using ASP.NET Core 2.0, and I have a request object annotated like this: public class MyRequest { [Required] public Guid Id { get; set; } [Required] public DateTime EndDateTimeUtc { get; set; } [Required] public DateTime StartDateTimeUtc { get; set; } } And in my controller: public async Task<IActionResult> HandleRequest([FromBody] MyRequest request) { /* ... */ } I noticed an issue with model binding: When I send a request containing the header Content-Type set to application/json and a