model-binding

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

╄→尐↘猪︶ㄣ 提交于 2019-12-04 04:59:01
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 { get; set; } [DataMember(Name = "session_key")] public string Sessionkey { get; set; } [DataMember(Name

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

天大地大妈咪最大 提交于 2019-12-04 03:12:15
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 : "Term" }), dataType: "json", success: function(jsonData) { ... } }); This works just fine and binds

Modelbinding IEnumerable in ASP.NET MVC POST?

女生的网名这么多〃 提交于 2019-12-04 02:30:46
Is there any issues with modelbinding IEnumerable types to an MVC POST? Some properties in my Model are not being bound upon a post to an action. Seems that properties on the model like strings are ok, but my IEnumerable is what is not being bound. Here's a snippet of my code: <%: Html.TextBoxFor(m => m.ResponseInfo.SubsetInfo.Test) %> <% for (int i = 0; i < Model.ResponseInfo.SubsetInfo.BandAvailabilities.Count(); i++) {%> <%: Html.TextBoxFor(m => m.ResponseInfo.SubsetInfo.BandAvailabilities.ToArray()[i].BandName) %> <% } %> And here is what those properties look like in the model: public

Inherited interface property not found by Model Binding in MVC3 but works fine in MVC2

天涯浪子 提交于 2019-12-04 02:27:10
UPDATE: Problem Solved. Darin Dimitrov's answer contains a link to another, related question. One of the proposed solutions on that page ended up working for us. Original Question The code sample below works in MVC 2 but throws an exception in MVC 3. Does anyone know why MVC 3 introduced this breaking change? Is there a way to get this working in MVC 3 while still allowing me to describe the viewmodel as an Interface from within the view? There is another related question on StackOverflow, but it doesn't give me any info as to why there is a difference between MVC 2 and MVC 3. Model public

How specify two css classes: from property and conditional class

我怕爱的太早我们不能终老 提交于 2019-12-04 01:56:49
I know that in knockout has the ability to specify class from observable property, like this: <div data-bind="css: Color " > Knockout also provides the ability to specify conditional class rendering like this: <div data-bind="css: { 'my-class' : SomeBooleanProperty }" > But which markup should be specified if i need those features of knockout css binding together? I tried this, but with no luck: <div data-bind="css: { Color, 'my-class' : SomeBooleanProperty }" > I have got the error: Error: Unable to parse bindings. SyntaxError: Unexpected token ,; I not found any example in google or in

AngularJS: ng-repeat with key value - updating object

不想你离开。 提交于 2019-12-04 01:55:27
I am rendering key:value object array with ng-repeat like this: <div ng-controller="mainCtrl"> <div ng-repeat="record in records"> <div ng-repeat="(key, value) in record"> <input ng-model="key" />: <input ng-model="value" /> </div> </div> </div> JS: var mainCtrl = function($scope){ $scope.records = [ {'key1':'val1'}, {'key2':'val2'} ]; } Problem is that keys and values cannot be updated through input tags. For some reason it becomes one way binding after making ng-repeat iterate over (key,value). Fiddle: http://jsfiddle.net/BSbqU/1/ How can I make it a two way binding? Or should I approach

ngModel with a bind function not working in ng2

丶灬走出姿态 提交于 2019-12-04 01:37:38
If I do in a template of a component something like: <input [(ngModel)]="myProperty"></input> then it works, but if I do it with a function in my component it does not: <input [(ngModel)]="getMyProperty()"></input> Here is the plunkr. Tested on RC6. Why? Try this construction <input [ngModel]="getMyProperty()"></input> use only square brackets. 来源: https://stackoverflow.com/questions/39468450/ngmodel-with-a-bind-function-not-working-in-ng2

.NET Model Binders

耗尽温柔 提交于 2019-12-04 01:27:55
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(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext); All related classes like

ASP.NET MVC Model Binding with Dashes in Form Element Names

时光毁灭记忆、已成空白 提交于 2019-12-04 00:41:30
I have been scouring the internet trying to find a way to accomodate dashes from my form elements into the default model binding behavior of ASP.NET's Controllers in MVC 2, 3, or even 4. As a front-end developer, I prefer dashes in my CSS over camelCase or underscores. In my markup, what I want to be able to do to is something like this: <input type="text" name="first-name" class="required" /> <input type="text" name="last-name" class="required" /> In the controller, I would be passing in a C# object that would look like this: public class Person { public string FirstName { get; set; } public

Apply Custom Model Binder to Object Property in asp.net core

十年热恋 提交于 2019-12-03 22:28:49
问题 I am trying to apply custom model binder for DateTime type property of model. Here is the IModelBinder and IModelBinderProvider implementations. public class DateTimeModelBinderProvider : IModelBinderProvider { public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(DateTime)) { return new BinderTypeModelBinder(typeof(DateTime)); } return null; } } public class