model-binding

How to configure a One-to-Many relationship in EF

假装没事ソ 提交于 2019-11-27 07:38:56
问题 I have the following model public class PageConfig : Base { // Properties Etc.. public ICollection<Image> ScrollerImages { get; set; } } My approach is to bind using a junction table { PageConfigID, ImageID }. In my model binder i tried the following.. modelBuilder.Entity<PageConfig>() .HasMany(x => x.ScrollerImages) .WithMany() .Map(x => { x.ToTable("junc_PageConfigScrollerImages"); x.MapLeftKey("PageConfigID"); x.MapRightKey("ImageID"); }); Which results in a null collection of images. How

Model Binding to Enums in ASP.NET MVC 3

。_饼干妹妹 提交于 2019-11-27 06:27:22
I have a method in my controller that accepts an object as an argument and returns a JsonResult . One of the properties on this object is an enum with three possible values. I assumed that when the client passed in an int for that property it would populate the enum, but it doesn't, it defaults to 0 and the enum is set to the first of it's possible selections. Any suggestions? Chev NOTE: This has been resolved in MVC 4. If upgrading to MVC 4 is a viable option for your project then that is all you have to do in order to begin model-binding to enums. That said, here is the workaround for MVC 3

How does a multiple select list work with model binding in ASP.NET MVC?

…衆ロ難τιáo~ 提交于 2019-11-27 05:18:13
问题 If you have a select list set to multiple in ASP.NET MVC, how does the modelbinding work? What does it return for your selected items, an array? <SELECT NAME="toppings" MULTIPLE SIZE=5> <option value="mushrooms">mushrooms</option> <option value="greenpeppers">green peppers</option> <option value="onions">onions</option> <option value="tomatoes">tomatoes</option> <option value="olives">olives</option> </SELECT> 回答1: Yes, by default a multiselectlist will post through an array of the selected

Model binding comma separated query string parameter

蓝咒 提交于 2019-11-27 05:17:00
问题 How can I bind query string parameter that is comma separated value http://localhost/Action?ids=4783,5063,5305 to a controller action expecting a list? public ActionResult Action(List<long> ids) { return View(); } Note! ids in the controller action must a list (or something IEnumerable based), so string ids is not accepted as an answer because these parameters are passed to many actions and parsing string to an array would add unwanted noise. 回答1: Here's my improved version of Nathan Taylor’s

error with decimal in mvc3 - the value is not valid for field

不羁岁月 提交于 2019-11-27 04:36:24
I'm following [Getting started with ASP.NET MVC 3][1]. And I can't add/edit with value of Price = 9.99 or 9,99. It said: "The value '9.99' is not valid for Price." and "The field Price must be a number." How to fix this? Model: public class Movie { public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public decimal Price { get; set; } } public class MovieDbContext : DbContext { public DbSet<Movie> Movies { get; set; } } Controller: public class MovieController : Controller { private MovieDbContext db = new

ASP.NET MVC 3 Model Binding Resources

烈酒焚心 提交于 2019-11-27 04:34:33
I am looking for a good resource that describes very thoroughly how model binding works with ASP.NET MVC 3 (or to a lesser extent, MVC 2) and different approaches. I have not been able to find any good resources on this topic, except bits and pieces there. The information on the net is more about "how to do X" than explaining how the internals of model binding work. Any recommendations? Book recommendations are fine as well. Take a look: ASP.NET MVC Model Binding - Part1 and Part2 http://www.codeproject.com/KB/aspnet/AspNetMVCModelBinding.aspx http://www.codeproject.com/KB/aspnet

Bind Angularjs to newly created html element dynamically

℡╲_俬逩灬. 提交于 2019-11-27 04:15:20
I have a tab page with multiple tabs that once clicked on call a service to return some data. Some of that data returns html forms and are very random. I want to collect those values that are entered and send the data via a service back to the server. The problem I have is that I can't get the data from the input elements in the html I'm creating dynamically. I've created a Plunker to show what the issue is. Note that the html value can change at any time so hard-coding the html won't work. Here the code from the plunker, but please look at the plunker for the best view of whats going on. app

Custom model binder for a property

时光怂恿深爱的人放手 提交于 2019-11-27 04:03:12
I have the following controller action: [HttpPost] public ViewResult DoSomething(MyModel model) { // do something return View(); } Where MyModel looks like this: public class MyModel { public string PropertyA {get; set;} public IList<int> PropertyB {get; set;} } So DefaultModelBinder should bind this without a problem. The only thing is that I want to use special/custom binder for binding PropertyB and I also want to reuse this binder. So I thought that solution would be to put a ModelBinder attribute before the PropertyB which of course doesn't work (ModelBinder attribute is not allowed on a

Changing the parameter name Web Api model binding

℡╲_俬逩灬. 提交于 2019-11-27 03:16:39
问题 I'm using Web API model binding to parse query parameters from a URL. For example, here is a model class: public class QueryParameters { [Required] public string Cap { get; set; } [Required] public string Id { get; set; } } This works fine when I call something like /api/values/5?cap=somecap&id=1 . Is there some way I can change the name of the property in the model class but keep the query parameter name the same - for example: public class QueryParameters { [Required] public string

Does model binding work via query string in asp.net mvc

流过昼夜 提交于 2019-11-27 03:12:35
问题 Does model binding work via query string as well ? If I have a get request like : GET /Country/CheckName?Country.Name=abc&Country.Id=0 HTTP/1.1 Would the following method in CountryController have its oCountry argument containing Id and Name properties with values from the query string ? public ViewResult CheckCountryName(Country oCountry) { //some code return View(oCountry); } For some reason I am getting Id as 0 and Name as null in oCountry object. What is missing ? 回答1: Yes, the model