The custom binding class needs to inherit form IModelBinder. Here we capture the current request and extract the Form fields individually. Then we can manipulate these fields any way we like.
I have a controller action method
[HttpPost]
public ActionResult Create(MyItem item){
...
}
My type definitions look like this
public class MyItem{
...
public List MySubItems{ get; set; }
}
public class MySubItem{
…
Morning/Afternoon/Evening all,
I'm pretty new to working within model binders and creating a custom model binder, so some things wont be clear to me.
I'm attempting to create a custom model binder in order to validate/review each string property…
Is there any reason why I'm not getting an injected service into my custom RegisterBinderProvider?
services.AddScoped();
services.AddMvc(options =>
{
…
EDIT: So it turns out that my ModelBinder isn't actually the problem. The issue is with my ValueConverter. Leaving this here, as I think it illustrates how to do a custom model binder though.
There is a lot of code in this question. I'm trying to…
I'm sending a json in the view with an ajax request and need to use it in the controller. But this json has dynamic parameters that means somethings it could have 10 or more properties so I cannot define a model. How can I get access to the…
I created a custom string object, but it does not modelbind when I post it back to the server. Is there an attribute I'm missing on the class or something?
This is the custom string class below:
public class EMailAddress
{
private string…
I am creating API in which has following url
/api/abc/?q=1&a=2&b=3&b=4
^^^^^^^
Input.cs(class used in ModelBinding)
...
public string A { get; set; }
public string B { get; set; }
public string Q { get; set; }
...
I am using…
I can able to find lot of related answers to trim extra spaces in model input in ASP.NET MVC API.
Referred below links,
How to trim spaces of model in ASP.NET MVC Web API
Best way to trim strings after data entry. Should I create a custom model…
I have an application with a custom database routing:
routes.Add("RouteWeb", new RouteWeb());
public override RouteData GetRouteData(HttpContextBase httpContext)
{
if (httpContext.Request.IsAjaxRequest() || httpContext.Request.Url == null)…
I've created a custom model binder based on an article from Haacked. Here's the code:
namespace MyNamespace.Project.ModelBinders
{
public class DecimalModelBinder : DefaultModelBinder
{
public override object…
I have a scenario where I have a certain base class we will call it "PagingCriteriaBase"
public class PagingCriteriaBase : CriteriaBase
{
public Int32 CountOfItemsPerPage { get; set; }
public SortOrder SortingOrder { get; set; }
public…
I have created a ModelBinder, which only gets triggered if an object has a [Decimal] attribute assigned, yet for some reason, despite it actually sanitising the data it does not seem to update the posted model.
I wonder if someone could see from my…
I am getting
An exception of type 'System.NullReferenceException' occurred in *****Tests.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
How to correctly assign values to the…
I'm trying to create model object using custom binder:
public class AccidentProtocolStep4ModelBinder : DefaultModelBinder
{
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext,
…
I'm using ASP.NET MVC 2 and want to figure out how to re-trigger the validation on my model after it has been populated using a custom binder.
So, I start with a couple of EF classes which are associated, Booking and Traveller (each booking can have…