model-binding

Inject a dependency into a custom model binder and using InRequestScope using Ninject

落花浮王杯 提交于 2019-12-28 04:25:28
问题 I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project in which I want an instance of IPostRepository to be shared between a controller and a custom model binder during the same web request. In my real project, I need this because I'm getting IEntityChangeTracker problems where I effectively have two repositories accessing the same object graph. So to keep my test project simple, I'm just trying to share a dummy repository. The problem I'm having is that it

Calling UpdateModel with a collection of complex data types reset all non-bound values?

可紊 提交于 2019-12-28 02:53:05
问题 I'm not sure if this is a bug in the DefaultModelBinder class or what. But UpdateModel usually doesn't change any values of the model except the ones it found a match for. Take a look at the following: [AcceptVerbs(HttpVerbs.Post)] public ViewResult Edit(List<int> Ids) { // Load list of persons from the database List<Person> people = GetFromDatabase(Ids); // shouldn't this update only the Name & Age properties of each Person object // in the collection and leave the rest of the properties (e

Afterwards Model Binding in ASP.NET MVC: How to convert QueryString values into a view model?

[亡魂溺海] 提交于 2019-12-25 17:34:48
问题 I have an action method without parameters. The QueryString collection contain all of my values. The keys of the QueryString match my view model properties. var queryStringValueProvider = new QueryStringValueProvider(ControllerContext); var providerResult = queryStringValueProvider.GetValue(ValidationKeys.Id); // ?! var viewModelTypeName = queryString[ValidationKeys.ViewModelType]; var viewModelType = Type.GetType(viewModelTypeName); var viewModelInstance = providerResult.ConvertTo

Asp.Net MVC 3 not binding collections to models on posting

佐手、 提交于 2019-12-25 17:18:28
问题 i have a object with many properties of which one is an array of some other complex object something like this class obj1 { public string prop1 {get; set;} public string prop2 {get; set;} public obj2[] array {get; set;} } class obj2 { SomeEnum Type{get; set;} string Content{get; set;} } I have created an editor template for the array of obj2 lets name it obj2ArrayTemplate which is like this @for (int i = 0; i < Model.Length; i++) { @Html.EditorFor(model=>model[i],"obj2Template") } and an

MVC-binder fails to bind complex-viewmodel-property in form submit

本秂侑毒 提交于 2019-12-25 08:47:52
问题 I'm using Umbraco MVC to build a form four our webpage. I have a ViewModel which is actually a property to another ViewModel, and is populated using a partial-view in the razor-form below. For whatever reason, the sub-viewmodel (RequiredHealthInputData, se below) is always null after binding! The binder will successfully bind all the form values to my main viewmodel but my sub-viewmodel will remain null! (I have research many similar questions regarding binding of complex types but I believe

null values from listbox, are not evaluated in the model binding of ASP.NET-MVC

别等时光非礼了梦想. 提交于 2019-12-25 06:39:22
问题 The model validation doesn't evaluates the attributes linked to listbox values if you don't select at least one of them. This way is not possible to do a model evaluation using DataAnnotations in order to inform required values. The controller: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using TestValidation.Models; namespace TestValidation.Controllers { [HandleError] public class HomeController : Controller { private SelectList

ASP.NET Web API deep model binding

拥有回忆 提交于 2019-12-25 04:22:39
问题 I've noticed (even in Web API 2.1) that deep parameter types get filled (processed by the model binder) only on the first level. That is : public class Person { public string Name { get; set; } public PersonDetails Details { get; set; } } public class PersonDetails { public string Address { get; set; } public int Age { get; set; } } // ... public class PersonController : ApiController { [HttpPost] public void ProcessPerson(Person person) { // person.Name is filled in correctly // person

ASP.NET Web API deep model binding

回眸只為那壹抹淺笑 提交于 2019-12-25 04:22:04
问题 I've noticed (even in Web API 2.1) that deep parameter types get filled (processed by the model binder) only on the first level. That is : public class Person { public string Name { get; set; } public PersonDetails Details { get; set; } } public class PersonDetails { public string Address { get; set; } public int Age { get; set; } } // ... public class PersonController : ApiController { [HttpPost] public void ProcessPerson(Person person) { // person.Name is filled in correctly // person

Binding public fields with ASP.NET MVC as well as public properties?

走远了吗. 提交于 2019-12-25 03:34:26
问题 Obviously, ASP.NET MVC's binding functionality takes care of binding a model's public properties when passing it to a controller, so for instance in the following example, Surname and Email will be bound with their submitted values: public ActionResult Create(UserModel mdlNewUser) { // ... } // ... public class UserModel { public string Firstname; public string Surname { get; set; } public string Email { get; set; } } However, it doesn't seem to auto-bind public fields such as Firstname in

Binding query string to object in ASP.NET MVC?

五迷三道 提交于 2019-12-25 02:24:49
问题 I have a grid control that I have bound to a model of IEnumerable. How ever in my controller I would like to save a record. The grid control I am using is one from Telerik 'Kendo'. The request back is a string and I would like to get my bound object 'CustomerViewModel' how ever when I pass in my object it comes back null. I have tried different types of information and it seems to only work for i specify the property I would like to pass in. Please find code below and assist? [AcceptVerbs