I'm having some difficulty writing some Unit Tests to test a custom ModelBinder that I created. The ModelBinder I'm trying to Unit Test is the JsonDictionaryModelBinder that I posted here.
The problem I'm having is getting the Mocking all setup using Moq. I keep getting Null Exceptions due to the HttpContextBase not being Mocked correct...
I have a fairly complex ViewModel containing decimal properties, which are exposed to the user in the form of text boxes. I want a textbox with no value to be interpreted as zero. (The properties in the underlying domain object are non-nullable, and the default value is 0.)
When the DefaultModelBinder binds the view data to the ViewMode...
I have modified the Nerd Dinner application to allow editing of child records by adding the following code to the DinnerForm.ascx
<p>
<%int i = 0;
foreach (NerdDinner.Models.RSVP rsvp in this.Model.Dinner.RSVPs)
{ %>
<%= Html.Hidden("Dinner.RSVPs[" + i + "].RsvpID", rsvp.RsvpID)%>
<%= Html.Hidden("Dinner...
I have two instances of an Address.ascx control in an ASP.NET MVC page.
<h1>Shipping Address</h1>
<% Html.RenderPartial("Controls/AddressControl"); %>
<h1>Billing Address</h1>
<% Html.RenderPartial("Controls/AddressControl"); %>
Of course, with the code exactly like this I'll end up with the same IDs for each field in the...
If I have a class similar to this:
public class Person
{
public string firstName { get; set; }
public string lastName { get; set; }
public Pet myPet { get; set; }
}
When I create a custom model binder, the Post from my form will not be sending in a Pet, it would send in data like this: firstName: "myFirstName" lastName: "m...
Hello,
I have unit tests covering my model binders. I create a ModelBindingContext and populate the ValueProviderDictionary with my test values. I feel confident that once my controller gets the model, everything is covered with testing and the right things are happening. I also feel confident that if the BindingContext is correct my...
I am using asp.net's modelbinder functionality to bind form values to my entity when posting from a view.
The html renders correctly in the initial view with correct option and value items.
When completing the form and posting, all values are populated correctly into the entity except the value from the dropdown list. not sure what I ...
The behavior described here appears to now be the default for ASP.NET MVC 2 (at least for Preview 1).
When modelbinding a querystring like this :
?Foo=&Bar=cat
The following binding occurs (assuming you're binding to a model with 'Foo' and 'Bar' string properties)
ASP.NET MVC 1
model.Foo = "";
model.Bar = "cat":
ASP.NET MVC 2...
Hi,
I've got a series of views, each are typed to have their own ViewModel class which contains everything they need to display themselves, for example:
public class CreateResourceViewModel
{
public Project Parent { get; set; }
public SelectList Categories { get; set; }
public Resource Resource { get; set; }
}
The post...
Hi all,
Is there a pre-built ModelBinder I can use with LINQ to get an object from a DataContext and update it on a HTTP post?
For example, currently I have this block of code:
[AcceptVerbs (HttpVerbs.Post)]
public ActionResult Edit (Project project)
{
var projectService = Factory.GetService<IProjectService> ();
project = proj...
Hello.
I'm developing a little site using ASP.NET MVC, MySQL and NHibernate.
I have a Contact class:
[ModelBinder(typeof(CondicaoBinder))]
public class Contact {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int Age { get; set; }
}
And a Model Binder:
public class Contac...
In his wonderful MVC book Steven Sanderson gives an example of a custom model binder that sets and retrieves a session variable, hiding the data storage element from the controller.
I'm trying to extend this to cater for a pretty common scenario: I'm storing a User object in the session and making this available to every action method a...
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 having a textbox inside a form.
[View]
<%=html.textbox("name") %>
[Controller]
Index(string name)
{
name = "something";
return View();
}
On Form Submit
In this case without sending any ViewData the textbox value is maintained.But the value "something" is not setting up.
But whn i change the Action to
[Cont...
Given a URL:
http://www.stackoverflow.com/question?ask=123&answers=5
and its corresponding ActionMethod and Model:
public ActionResult Question(RequestObject request)
{
return View("Question", request);
}
public class RequestObject
{
public string AskId
{
get;
set;
}
public string NumberOfAnswers
...
I need to create something similar to how MVC invokes an Method(Action) and also uses the Model Binder to map a NamedValueCollection to the parameters on that method. Basically I have a Controller action that needs to dynamically call a method on a class, the controller has any information sent in a form or query string plus the name of ...
I had a nice function that took my FormCollection (provided from the controller). Now I want to do a model bind instead and have my model binder call that function and it needs the FormCollection. For some reason I can find it. I thought it would have been
controllerContext.HttpContext.Request.Form
...
The following is the code for my controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Actor actor)
{
try
{
actorRepository.Save(actor);
return RedirectToAction("Index");
}
catch
{
return View("Edit");
}
}
The view...
Hi guys
I am having more than a little difficulty trying to debug why MVC is not binding correctly in a given case I have...
Basically, I have my action which receives a complex object which in turn has a complex child object - Activity.Location.State (Where Activity is the complex object that the action expects, Location is a complex ...