model-binding

ASP.Net 4.5 Model Binding Sorting By Navigation Property

我的未来我决定 提交于 2019-11-30 22:02:19
All, I have a grid view that has the following columns. The paging work great, but not sorting. Everytime I click on the Category column to sort by category I would get this error: Instance property 'Category.CategoryName' is not defined for type 'ESA.Data.Models.Entity.Project' This error statement is not true because the gridview was able to display the column correctly. Here is the select method public IQueryable<Project> getProjects() { ApplicationServices objServices = new ApplicationServices(); IQueryable<Project> lstProject; lstProject = objServices.getProjects(); return lstProject; }

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

旧街凉风 提交于 2019-11-30 20:29:44
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, I understand the security implications). Understandably, I get an error because since the default

How to trim spaces of model in ASP.NET MVC Web API

99封情书 提交于 2019-11-30 20:07:06
What is the best way to trim all the properties of the model passed to the MVC web api (post method with complex object). One thing simply can be done is calling Trim function in the getter of all the properties. But, I really do not like that. I want the simple way something like the one mentioned for the MVC here ASP.NET MVC: Best way to trim strings after data entry. Should I create a custom model binder? To trim all incoming string values in Web API, you can define a Newtonsoft.Json.JsonConverter : class TrimmingConverter : JsonConverter { public override bool CanConvert(Type objectType) {

How do I ModelBind a many-to-many relationship with MVC 3 and Entity Framework Code First?

☆樱花仙子☆ 提交于 2019-11-30 18:32:37
问题 I'm coming across the same problem in my MVC 3 applications. I've got a view to create an new product and that product can be assigned to one or more categories. Here are my EF Code First Model Classes: public class Product { public int ProductID { get; set; } public string Name { get; set; } public virtual ICollection<Category> Categories { get; set; } } public class Category { public int CategoryID { get; set; } public string Name { get; set; } public virtual ICollection<Product> Products {

ASP.Net 4.5 Model Binding Sorting By Navigation Property

雨燕双飞 提交于 2019-11-30 17:27:50
问题 All, I have a grid view that has the following columns. The paging work great, but not sorting. Everytime I click on the Category column to sort by category I would get this error: Instance property 'Category.CategoryName' is not defined for type 'ESA.Data.Models.Entity.Project' This error statement is not true because the gridview was able to display the column correctly. Here is the select method public IQueryable<Project> getProjects() { ApplicationServices objServices = new

JTable setting model and preserve column formats (width, alignment, etc.)

穿精又带淫゛_ 提交于 2019-11-30 16:30:56
This is a brain-cracking experience with JTable binding. Here's what I did. I created a JTable with columns set to a specified width, formatted it using renderers , and added some codes on it. But when i try to bind it to a model, all the columns were replaced by the fields of the model . Is there a way on how to correctly bind it? I'm avoiding loops because there are 100+ thousand records in the database. I'm trying to use other methods such as BeansBinding and EntityManager but I don't know how to change the datasource ( that's why i choose binding it to a model ) because I'm testing this to

How to gain control over model binding?

拜拜、爱过 提交于 2019-11-30 14:56:00
问题 I started using MVC recently and I'm getting little disappointed. Instead of helping me, the framework is getting in my way. I'm trying to write a controller action like this (pseudo code) ActionResult Save(long id, string whichForm) { if (whichForm == "A") { var vm = CreateModel(Request.Form); if (!TryValidate(vm)) return View(vm); else return RedirectToRoute("Success"); } else .... } Basically I'd like to have control over when my view-model is constructed and when it is validated. Is this

ASP.NET Web Forms 4.5 model binding where the model contains a collection

妖精的绣舞 提交于 2019-11-30 13:13:00
问题 I'm trying to update an old Web Forms application to use the new model binding features added in 4.5, similar to the MVC binding features. I'm having trouble making an editable FormView that presents a single model that contains simple members plus a member that is a collection of other models. I need the user to be able to edit the simple properties of the parent object and the properties of the child collection. The problem is that the child collection ( ProductChoice.Extras ) is always

Binding an editable list of children

拥有回忆 提交于 2019-11-30 12:59:05
TL;DR : In my ASP.NET MVC3 App, how should I implement a View that allows me to edit details of a 'parent' entity at the same time as the details of a list of 'children' entities ? Update : I'm accepting @torm's answer because he provided a link that gives some explanation as to why my current solution may be as good as it gets. However, we'd love to hear if anyone else have any alternative! I've been searching and reading (see the 'References' section at the bottom for some of the findings so far). However, I still feel like there's something 'smelly' with the solutions I found so far. I

MVC2 TextBoxFor value not updating after submit?

喜欢而已 提交于 2019-11-30 12:33:42
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... I apologize in advance for the toilet humor, but it keeps the day from getting too boring. ;) Does