When I use the default model binding to bind form parameters to a complex object which is a parameter to an action, the framework remembers the values passed to the first request, meaning that any subsequent request to that action gets the same data as the first. The parameter values and validation state are persisted between unrelated w...
I am extending the DefaultModelBinder class in order to do some custom model binding. I am overriding the BindProperty method like so:
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
{
if (prope...
Is there any way to get posted files (<input type="file" />) to take part in model binding in ASP.NET MVC without manually looking at the request context in a custom model binder, and without creating a separate action method which only takes a posted file as input?
I would have thought that this would work:
class MyModel {
public Ht...
Hi,
I have a custom modal class which contains a decimal member and a view to accept entry for this class. Everything worked well till I added javascripts to format the number inside input control. The format code format the inputted number with thousand separator ',' when focus blur.
The problem is that the decimal value inside my mod...
I have a View with a table representing an employee's timesheet. Days across the top, projects down the side, with each day/project intersection containing two values for regular hours and overtime.
The (simplified) class definitions for the page model are:
public class TimesheetFormModel {
public List<Project> Projects;
// oth...
Let's say I have an interface like:
interface IThing {
int Id { get; set; }
string Title { get; set; }
}
And in ASP.NET MVC I have a form that posts to a controller action like this:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult NewThing([Bind(Exclude = "Id")] SimpleThing thing) {
// code to validate and persist the...
I am trying to get UpdateModel to populate a model that is set as only an interface at compile-time. For example, I have:
// View Model
public class AccountViewModel {
public string Email { get; set; }
public IProfile Profile { get; set; }
}
// Interface
public interface IProfile {
// Empty
}
// Actual profile instance used
publ...
I am having a weird issue in ASP.NET MVC with objects not being updated with UpdateModel when passed a formCollection. UpdateModel does not appear to be working properly when the object being updated is created through reflection.
Scenario: I have an application which has approximately 50 lookup tables--each of which includes exactly th...
I'm not sure if this is a bug, or a feature. I have an action param that takes a ListRequest object with a few string properties. .NET MVC dutifully maps the query string params of the same name to the ListRequest objects' properties.
I add a ListRequest.Filters property, which is to be a list of strings taken from the querystring: ?fi...
First; I know that I should not need to test the internals of MVC but I REALLY need a suite a tests around data flowing into our system.
How can I, I hope without mocking all of HTTP context, test that objectA (form collection, dict, collection, object, etc) does or does not conform to objectAModel?
I'd like to not have to instantiate...
When I migrated sample SportsStore app from Steve Sanderson's Pro ASP.NET MVC Framework (from asp.net 1.0 to mvc 2 beta) using this app provided by eric lipton, everything work just fine - except 2 unit tests.
The error message on both is:
Tests.CartControllerTests.VeryLongTestMethodName:
System.ArgumentNullException: value can't be unde...
My strongly typed View inherits from a "Person" object that is created with Linq to SQL. In my "Edit" View, i have to display of course old values:
<%= Html.TextBox("FirstName") %>
"FirstName" is NCHAR, so it need to be trimmed. So i ended up with:
<%= Html.TextBox("FirstName", Model.FirstName.Trim()) %>
and this works. But when fo...
Hi All,
I am definitely missing some understanding of the automatic model binding of a view.
The issue:
I have a view model that has properties as follows:
public class ItemViewModel
{
public TextBoxControlData FundName { get; set; }
public List<DateControlData> Dates { get; set; }
}
where TextBoxControlData and DateControl...
I have what I would think is a somewhat normal situation where I need to bind form posts to an "order" model. This model has a few levels of information to it:
Order.Billing.FirstName
Order.Billing.Address.City
Order.Billing.Address.Country
Using the DefaultModelBinder, if I POST a form to an action that takes this Order model as the ...
I have a simple Poco-Model using abstract classes, and it seems not to work with the Default ModelBinder of Asp.net MVC 2.
One Item has several Objects in a collection, all using the same abstract base class.
Model:
public partial class Item
{
public virtual ICollection<Core.Object> Objects
{
get
...
I want a list of different (derived) object types working with the Default Modelbinder in Asp.net MVC 2.
I have the following ViewModel:
public class ItemFormModel
{
[Required(ErrorMessage = "Required Field")]
public string Name { get; set; }
public string Description { get; set; }
[Scaffold...
There are a few related questions, but I can't find an answer that works.
Assuming I have the following models:
public class EditorViewModel
{
public Account Account {get;set;}
public string SomeSimpleStuff {get;set;}
}
public class Account
{
public string AccountName {get;set;}
public int MorePrimitivesFollow {get;set;}
}
a...
I have a struct which works much like the System.Nullable type:
public struct SpecialProperty<T>
{
public static implicit operator T(SpecialProperty<T> value)
{
return value.Value;
}
public static implicit operator SpecialProperty<T>(T value)
{
return new TrackChanges<T> { Value = value };
}
...
I'm developing a project using BDD/TDD techniques and I'm trying my best to stay the course. A problem I just ran into is unit testing the DefaultModelBinder. I'm using mspec to write my tests.
I have a class like this that I want to bind to:
public class EmailMessageInput : IMessageInput
{
public object Recipient
...
I'm having some trouble unit testing the model returned by DefaultModelBinder. I want to feed in a fake form collection and check the model that it returns to make sure model properties are being bound properly. In my research, I'm not turning up -any- resources on testing the DefaultModelBinder. Maybe I'm missing something. Maybe I shou...