model-binding

Asp.net MVC Model binding derived class

守給你的承諾、 提交于 2019-12-11 12:13:27
问题 I've write an abstract class PaymentMethod and 2 derived classes, PaymentMethodInvoice and PaymentMethodBilling . For each of them i've write shared EditorTemplates. The GET works fine, I select my PaymentMethod and get the right form. If I POST this form the model binding doesn't work, it trys to instantiate the abstract class PaymentMethod . Must I override the CreateModel ( protected override object CreateModel )[1] or is there a better solution to handle this? [1] MVC 3 Model Binding a

List count empty when passing from view to model in ASP.Net MVC

走远了吗. 提交于 2019-12-11 11:53:29
问题 Before I begin, I have looked at this question: asp.net mvc model binding fails for <List> items in editor template I have a model which looks as so: public class PartnerListModel { public List<PartnersModel> Partners { get; set; } public PartnerListModel() { Partners = new List<PartnersModel>(); } } And then my PartnersModel looks as such: public class PartnersModel { public int ID { get; set; } public string Name { get; set; } public bool IsActive { get; set; } } I'm passing the

.NET MVC: how to get the model binder to assign null to a list property?

 ̄綄美尐妖づ 提交于 2019-12-11 10:31:46
问题 I have a model like so: class Model { public IList<Item> Items { get; set; } } class Item { public int Id { get; set; } } I am sending a request to an action method that takes a Model as a parameter. The request contains the following key-value pair: " Items=" (i. e. Items=null ). The default model binder sets Items to be a list of 1 null item, where I want the list property itself to be null (or at least empty). Is there any way to accomplish this? Obviously, I could do some sort of custom

Can't get selected drop down value to bind to view model property

冷暖自知 提交于 2019-12-11 10:27:27
问题 I'm having trouble binding the selected value of a drop down list to the correct property in my view model. I can't see what I am doing wrong here. I've put the code that should help show what I'm doing below. I've omitted some things such as the population of the 'AllFolders' property of the view model, as it's just a simple List with an object called ImageGalleryFolder . Every time the form posts back, the ParentFolderId property is null without fail. This is driving me crazy and I've

Overriding MVC DefaultModelBinder to handle arrays of complex objects

自古美人都是妖i 提交于 2019-12-11 10:21:36
问题 The default MVC model binder ( System.Web.Mvc.DefaultModelBiner ) correctly binds the following syntax of nested arrays: array[0].propertyA=valueA&array[0].propertyB=valueB& ...etc To the following action method: public ActionResult AjaxHandler(Part[] array, ...) However, jQuery.param() is only able to serialize into the following syntax : array[0][propertyA]=valueA&array[0][propertyB]=valueB& ...etc Setting traditional flag to true still produces incorrect mapping: array=[object+Object]&..

binding to list of nested objects

守給你的承諾、 提交于 2019-12-11 10:15:44
问题 as I'm not sure how binding to nested objects works let me explain my predicament: Here is my class: public class DeliveryContactViewModel { public List<DeliveryContact> Contacts; public string Name { get; set; } } public class DeliveryContact { public string ContactType { get; set; } public string ContactAddress { get; set; } public List<bool> Reasons { get; set; } } OK, so nothing extra special here... Let's tackle View part now: My idea was to make a form (pseudocode following) <form

ModelBinding not deserializing json

梦想与她 提交于 2019-12-11 09:15:10
问题 I'm using MVC 5, Web API 2 with Entity Framework 6 in vs 2012. I'm able to successfully call the right action in my web api controller but the incoming json is never deserialized, or at least not properly. The modelBinding recognizes that the json in the request matches the argument Type for the Post action but every property is null or default value. Why is the json not being deserialized? I can't see any issues here. This not an active url, just something setup on my local POST http://www

Custom Model Binding MVC

此生再无相见时 提交于 2019-12-11 08:39:42
问题 I'm trying to pass a list of JSON objects to a controller method, and automatically have the correct types defined and populated in the controller. JSON Posted to controller: { Type : 'Image', ImageName : 'blah.jpg' }, { Type : 'Text', Text: 'Hello', Font: 'Some Font' }.. The Controller: public ActionResult SaveCOntent(IList<Item> content) So the impression i've got is that I need to use ModelBinding to convert the elements into the correct type. I've tried following another suggested post

Model passed to a partial view is null upon form submit

我们两清 提交于 2019-12-11 08:28:19
问题 I have the following model: @model SmartSEOModel public class SmartSEOModel { public SmartSEOSettingsModel SmartSEOSettingsModel { get; set; } public SEOTemplateModel SEOTemplateModel { get; set; } } In my view I have a partial view which I call like this: @using (Html.BeginForm()) { some razor code here <div id="pnlSmartSEO"> @Html.Partial(ViewNames.SmartSEOController_SEOTemplate, Model.SEOTemplateModel) </div> } In the partial view there are some form fields bound to the SEOTemplateModel.

Can I get access to the data that the .net web api model binding was not able to handle?

拟墨画扇 提交于 2019-12-11 08:17:57
问题 I have a MVC 4 web api application that receives json objects and uses the standard model binding facility to bind them to my poco objects for easy use in my controller methods. This all works great, when the json structures I am receiving map directly to my poco. for example I have a controller method public HttpResponseMessage Post(DeviceConfigurationDto deviceConfiguration) and DeviceConfigurationDto is public class DeviceConfigurationDto { public long Timestamp { get; set; } public string