Questions tagged [modelbinder]
61 questions
14
votes
3 answers
how to sanitize input data in web api using anti xss attack
Below is the snippet of my code
Model class
// Customer.cs
using CommonLayer;
namespace Models
{
public class Customer
{
public int Id { get; set; }
[MyAntiXss]
public string Name { get; set; }
}
}
I want to…

Ankur Bhutani
- 3,079
- 4
- 29
- 26
12
votes
3 answers
MVC 3.0 ModelBinder bindingContext.ValueProvider.GetValue(key) returns null when binding in a collection
I am new using custom ModelBinders, I have been looking around and I couldn't find any post related to this specific case.
I have an entity like:
public class DynamicData
{
public IList DynamicDataItems{get;set;}
…

Dzyann
- 5,062
- 11
- 63
- 95
11
votes
1 answer
When do I use View Models, Partials, Templates and handle child bindings with MVC 3
new to mvc3, i have a few questions, would appreciate if someone could answer/provide links:
When should I use View Models? Is it not recommended to use the domain? I find that my view models are copies of my domain objects, and don't see the…

newbie_86
- 4,520
- 17
- 58
- 89
10
votes
2 answers
WebAPI ModelBinder Error
I've implemented a ModelBinder but it's BindModel() method is not being called, and I get Error Code 500 with the following message:
Error:
Could not
create a 'IModelBinder' from 'MyModelBinder'. Please ensure it derives
from 'IModelBinder' and has…

Aviran Cohen
- 5,581
- 4
- 48
- 75
9
votes
5 answers
Does the Model Binder in ASP.NET MVC Beta Support List?
Take the example classes below. I want to display the customer and two addresses (from a LIST) on a form. Does the model binder in MVC beta support this or will I have to write my own custom binder?
public class Customer
{
public string…

37Stars
- 2,489
- 20
- 23
5
votes
0 answers
How to code a Polymorphic Model Binder and Provider in MVC 6
This question has been asked before on SO and elsewhere in the context of MVC3 and there are bits and bobs about it related to ASP.NET Core RC1 and RC2 but niot a single example that actually shows how to do it the right way in MVC 6.
There are the…

user3099312
- 73
- 6
4
votes
3 answers
Upgraded MVC 2 to MVC3 gets Model binder exception
After upgrade I get this error for some of the views.
Value cannot be null. Parameter name: value
Stack trace
[ArgumentNullException: Value cannot be null.
Parameter name: value]
…

Anders
- 17,306
- 10
- 76
- 144
4
votes
3 answers
How to convert a http-request into the right object?
In my ASP.Net MVC3 project I have created a ModelBinder which binds a basemodel. In my View i create a object from a Model that inherit from my basemodel. Now i wan´t to know which Model was created via reflection in my ModelBinder when i press the…

jwillmer
- 3,570
- 5
- 37
- 73
4
votes
2 answers
How to make a controller accept post data from the body as well as URL in MVC 6 ASP.NET 5
Currently I am trying to write a controller in MVC 6 that is capable of accepting data from a post request. The issue is that depending on the client (which is not always a web browser), the data can come in as either key value pairs in the request…

Ryan
- 3,852
- 4
- 18
- 18
4
votes
3 answers
ASP.NET MVC 2 RC model binding with NHibernate and dropdown lists
I have problem with model binding in my ASP.NET MVC 2 RC application that uses NHibernate for data access. We are trying to build the application in a Ruby on Rails way and have a very simple architecture where the domain entities are used all the…

HakonB
- 6,977
- 1
- 26
- 27
4
votes
1 answer
bindmodel vs createmodel asp mvc 3
I am developping my first application in Asp. I am using the environment Asp.NET MVC 3.
I have a controller Action that has a single parameter. The type of this parameter is a complex object.
public ActionResult MyAction(ComplexObj obj) {
…

minchiya
- 603
- 1
- 7
- 13
4
votes
1 answer
.NET MVC unobtrusive validation and custom model binder
I have a simple MVC website that displays a jquery dialog for editing purposes. In this dialog is a textarea that accepts a comma delimited list of skills that the user can enter. Upon submission, my model binder turns this into a List. Here is the…

jamesamuir
- 1,397
- 3
- 19
- 41
3
votes
4 answers
ASP.Net MVC DefaultModelBinder not binding properties on POST
I'm facing a really strange problem that has me smoked.
I have a fairly simple scenario where I have a strongly typed view that is correctly populated from the controller on the GET, but then when it POSTS the form to the controller, the Reqeust…

Paul
- 35,689
- 11
- 93
- 122
3
votes
1 answer
Exclude properties on model binding using interfaces
This is an example I have lifted here: http://aspalliance.com/1776_ASPNET_MVC_Beta_Released.5
public ActionResult Save(int id)
{
Person person = GetPersonFromDatabase(id);
try
{
UpdateMode(person)
…

Aivan Monceller
- 4,636
- 10
- 42
- 69
3
votes
2 answers
Model binder does not convert json to IEnumerable
I am sending json data to my controller action via jquery ajax post. The IEnumerable in my action is alway null.
Is my json wrong or why does the model binder not convert the json to the IEnumerable ?
public ActionResult Update(IEnumerable…

Elisabeth
- 20,496
- 52
- 200
- 321