model-binding

.input-validation-error to a textbox when the form is redisplayed for failed value

孤人 提交于 2019-12-19 05:57:17
问题 I've asked a question to know why, in my application, textboxes are being highlighted (i.e. red border and pink-shaded backgroung are applied to the textbox) when I use modelbinding to validate the model ( TryUpdateModel() ) but not when I validate manually ( ModelState.AddModelError ). It has been 2 days now without any answer. I've tried every thing myself without succes. So, I decide to ask the question differently. The way I understand IT, here's how ModelBinding treats a request.

is it possible to have modelbinding in asp.net webapi with uploaded file?

时光怂恿深爱的人放手 提交于 2019-12-19 05:44:21
问题 the model: public class UploadFileModel { public int Id { get; set; } public string FileName { get; set; } public HttpPostedFileBase File { get; set; } } the controller: public void Post(UploadFileModel model) { // never arrives... } I am getting an error "No MediaTypeFormatter is available to read an object of type 'UploadFileModel' from content with media type 'multipart/form-data'." Is there anyway around this? 回答1: It's not easily possible. Model binding in Web API is fundamentally

is it possible to have modelbinding in asp.net webapi with uploaded file?

六月ゝ 毕业季﹏ 提交于 2019-12-19 05:44:05
问题 the model: public class UploadFileModel { public int Id { get; set; } public string FileName { get; set; } public HttpPostedFileBase File { get; set; } } the controller: public void Post(UploadFileModel model) { // never arrives... } I am getting an error "No MediaTypeFormatter is available to read an object of type 'UploadFileModel' from content with media type 'multipart/form-data'." Is there anyway around this? 回答1: It's not easily possible. Model binding in Web API is fundamentally

ASP.NET Web API - ModelBinders

独自空忆成欢 提交于 2019-12-19 05:12:55
问题 I need to use a custom modelbinder of some kind to always treat incoming dates in UK format, i have setup a custom model binder and registered like so: GlobalConfiguration.Configuration.BindParameter(typeof(DateTime), new DateTimeModelBinder()); This only seems to work for querystring parameters, and only works if i specify [ModelBinder] on my parameter like so, is there i way to make all actions use my model binder: public IList<LeadsLeadRowViewModel> Get([ModelBinder]LeadsIndexViewModel

Web API ModelBinders - how to bind one property of your object differently

时间秒杀一切 提交于 2019-12-19 02:51:22
问题 I have the following action signature [ValidateInput(false)] public HttpResponseMessage PostParam(Param param) With Param looking something like this: public class Param { public int Id { get; set;} public string Name { get; set; } public string Choices { get; set; } } Here's the hitch - what comes over the wire is something like this { Id: 2, Name: "blah", Choices: [ { foo: "bar" }, { blah: "blo" something: 123 } ] } I don't want "Choices" to deserialize - I want it stored as a string (yes,

Posting a collection of subclasses

一个人想着一个人 提交于 2019-12-18 16:49:25
问题 I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as: QuoteForProductTypeA QuoteForProductTypeB All quote types share a common base class, such as QuoteBase. I have my quotes displaying fine on the front end, and appear to post back the correct data too. However, on the server it doesn't obviously doesn't know which subclass to use, so just uses the base class. I think i need some kind of custom model binder for WebApi to check for a

Posting a collection of subclasses

落花浮王杯 提交于 2019-12-18 16:49:22
问题 I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as: QuoteForProductTypeA QuoteForProductTypeB All quote types share a common base class, such as QuoteBase. I have my quotes displaying fine on the front end, and appear to post back the correct data too. However, on the server it doesn't obviously doesn't know which subclass to use, so just uses the base class. I think i need some kind of custom model binder for WebApi to check for a

MVC2 TextBoxFor value not updating after submit?

a 夏天 提交于 2019-12-18 14:54:12
问题 This is a really strange behavior, and I've set up some demo code to try to figure out what's going on. Basically have a a two actions and a single view. The first action sends an empty model to the view, the section action recieves the model, alters its contents and sends it back to the same view. The wierdness is, in the view, the Model seems to have the updated values in it, but when I do an Html.TextBoxFor(x => x.PropertyNameHere) it renders a textbox with the unaltered value in it. lol..

ASP.NET MVC 3 Model-binding and form fields

自古美人都是妖i 提交于 2019-12-18 13:20:36
问题 I have an entity called Domain.Models.BlogPost which contains the following properties: PostID Title Author PostedDate Body I also have an entity called Domain.Models.PostComment which contains the following properties: CommentID PostID Author Email Website Body BlogPost contains many PostComments . A one to many relationship. Now I have a view like this (separated comment form from blog post code via html comment): @model Domain.Models.BlogPost @using Domain.Models; @{ ViewBag.Title = "Post"

Why does the ASP.Net MVC model binder bind an empty JSON array to null?

此生再无相见时 提交于 2019-12-18 12:45:51
问题 Here is my model class: public class MyModel { public Employees[] MyEmpls{get;set;} public int Id{get;set;} public OrgName{get;set;} } Passing the below JSON structure object with MyEmpls as empty array to MVC controller. ["Id":12, "MyEmpls":[], "OrgName":"Kekran Mcran"] Controller [HttpPost] public ActionResult SaveOrg(MyModel model) { //model.MyEmpls is null here } I am expecting mode.MyEmpls to be an empty c# array, not a null. Is a custom model binder necessary to achieve an empty array?