value-provider

Problem with double values binding

微笑、不失礼 提交于 2019-12-29 06:54:36
问题 In my project I want to allow users input double values in 2 formats: with using ',' or '.' as delimiter (I'm not interested in exponential form). By default value with delimiter '.' don't work. I want this behavior works for all double properties in complex model objects (currently I work with collections of objects, that contains identifiers and values). What i should use: Value Providers or Model Binders? Please, show code example of solving my problem. 回答1: You could use a custom model

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: Order of execution of ValueProviders

我们两清 提交于 2019-12-10 04:06:45
问题 I like to know the order of the execution of the different ValueProviders in ASP.NET MVC. ValueProviders: QueryStringValueProvider RouteDataValueProvider FormValueProvider ... I did not find an information. 回答1: If memory serves me, the priority is like this. Form data in the request Route data Query String Http File Collection EDIT I appear to be in agreement with the following website, which lists the same order. http://www.howmvcworks.net/OnModelsAndViewModels/TheBeautyThatIsTheModelBinder

ASP.NET MVC: Order of execution of ValueProviders

空扰寡人 提交于 2019-12-05 03:25:12
I like to know the order of the execution of the different ValueProviders in ASP.NET MVC. ValueProviders: QueryStringValueProvider RouteDataValueProvider FormValueProvider ... I did not find an information. If memory serves me, the priority is like this. Form data in the request Route data Query String Http File Collection EDIT I appear to be in agreement with the following website, which lists the same order. http://www.howmvcworks.net/OnModelsAndViewModels/TheBeautyThatIsTheModelBinder You can check this out from ASP.NET MVC source code: ValueProviderFactories.cs Here is the predefined order

How to map a 1 or 0 in an ASP.Net MVC route segment into a Boolean action method input parameter

给你一囗甜甜゛ 提交于 2019-12-01 04:53:17
We have some PHP and Javascript apps that call into some ASP.NET MVC endpoints. Let's say we have this endpoint: public ActionResult DoSomething(bool flag) { } I want it to match the value for flag whether I pass in an integer of 1 or 0, or pass in a string of "true" or "false". What part of the framework do I need to implement in order to match that up? The best way to do this is using a custom value provider. While you can do this using a complete custom model binder, that is overkill based on your requirements, and it is much easier simply to implement a custom value provider. For some

How to map a 1 or 0 in an ASP.Net MVC route segment into a Boolean action method input parameter

烂漫一生 提交于 2019-12-01 01:09:34
问题 We have some PHP and Javascript apps that call into some ASP.NET MVC endpoints. Let's say we have this endpoint: public ActionResult DoSomething(bool flag) { } I want it to match the value for flag whether I pass in an integer of 1 or 0, or pass in a string of "true" or "false". What part of the framework do I need to implement in order to match that up? 回答1: The best way to do this is using a custom value provider. While you can do this using a complete custom model binder, that is overkill

Problem with double values binding

喜夏-厌秋 提交于 2019-11-29 06:57:42
In my project I want to allow users input double values in 2 formats: with using ',' or '.' as delimiter (I'm not interested in exponential form). By default value with delimiter '.' don't work. I want this behavior works for all double properties in complex model objects (currently I work with collections of objects, that contains identifiers and values). What i should use: Value Providers or Model Binders? Please, show code example of solving my problem. You could use a custom model binder: public class DoubleModelBinder : DefaultModelBinder { public override object BindModel

MVC Routing Parameter Precedence

守給你的承諾、 提交于 2019-11-26 19:12:32
I came across a scenario where I had the default MVC Route setup. Like So. routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); Then navigating to a url as such domain/controller/action/1234 On this page I was then navigating to the same page but with different parameters after a certain event. Like so. var id = $(this).data("id"); var url = "@Url.Action("action", "controller", new { area = ""})"; var params = $.param({id: id, vrnsearch: true}); var fullUrl = url += "?" + params; window

Accept comma and dot as decimal separator [duplicate]

风格不统一 提交于 2019-11-26 08:25:45
问题 This question already has an answer here: How to set decimal separators in ASP.NET MVC controllers? 4 answers Model binding in ASP.NET MVC is great, but it follows locale settings. In my locale decimal separator is comma (\',\'), but users use dot (\'.\') too, because they are lazy to switch layouts. I want this implemented in one place for all decimal fields in my models. Should I implement my own Value Provider (or event Model Binder) for decimal type or I\'ve missed some simple way to do

MVC Routing Parameter Precedence

隐身守侯 提交于 2019-11-26 06:48:56
问题 I came across a scenario where I had the default MVC Route setup. Like So. routes.MapRoute( name: \"Default\", url: \"{controller}/{action}/{id}\", defaults: new { controller = \"Home\", action = \"Index\", id = UrlParameter.Optional } ); Then navigating to a url as such domain/controller/action/1234 On this page I was then navigating to the same page but with different parameters after a certain event. Like so. var id = $(this).data(\"id\"); var url = \"@Url.Action(\"action\", \"controller\"