asp.net-mvc-2

MVC Custom Model Binder Binding Multiple Values

Hello everyone, I have a scenario in which I have multiple sources to bind to my model. For one, I have a view tied to a strongly-typed model, but this scenario also entails posting data to this view from a 3rd party site. Essentially, what I believe I am after in the custom model binding is to investigate the form values in the Reques...

ASP.Net MVC2 CustomModelBinder not working... Changed from MVC1

(My apologies if this seems verbose - trying to provide all relevant code) I've just upgraded to VS2010, and am now having trouble trying to get a new CustomModelBinder working. In MVC1 I would have written something like public class AwardModelBinder: DefaultModelBinder { : public override object BindModel(ControllerContext c...

asp.net mvc 2: SportsStore application: The current request for action is ambiguous

I am working on SportsStore example on chapter 4 from the following book and getting stuck... Pro Asp.net mvc framework I get the following error: The current request for action 'List' on controller type 'ProductsController' is ambiguous between the following action methods: System.Web.Mvc.ViewResult List() on type WebUI.Controllers....

MVC2 Client side validation within Jquery modal dialog

Using MVC2 I currently have a view creating a jquery dialog box containing an Edit partial view. On submit I am looking for it to perform client side validation on the Email class which has a required data annotation attribute for email address. Server side validation works fine but I want the user to have to fix the error in the modal...

Can I perform some processing on the POST data before ASP.NET MVC UpdateModel happens?

I would like to strip out non-numeric elements from the POST data before using UpdateModel to update the copy in the database. Is there a way to do this? // TODO: it appears I don't even use the parameter given at all, and all the magic // happens via UpdateModel and the "controller's current value provider"? [HttpPost] public ActionRes...

Using MVC2 to update an Entity Framework v4 object with foreign keys fails

With the following simple relational database structure: An Order has one or more OrderItems, and each OrderItem has one OrderItemStatus. Entity Framework v4 is used to communicate with the database and entities have been generated from this schema. The Entities connection happens to be called EnumTestEntities in the example. The trim...

How do you use Nant to build an ASP.Net MVC project?

Does anyone have an example nant build file to build an MVC2 project? I'm not sure whether you can use msbuild or whether you have to use aspnet_compiler or if nant will just handle it. Thanks ...

Asp.Net MVC 2 Html.TextBoxFor Best way to specify a format string for a DateTime property of model

As the question title explains, what is the best way to specify a format which my Views use when displaying values of a DateTime property via the Html.TextboxFor method. The default display includes the Date and Time where I really only want the Date displayed. Thanks ...

Cannot call action method 'System.Web.Mvc.PartialViewResult Foo[T](T)' on controller 'Controller' because the action method is a generic method

Cannot call action method 'System.Web.Mvc.PartialViewResult FooT' on controller 'Controller' because the action method is a generic method <% Html.RenderAction("Foo", model = Model}); %> Is there a workaround for this limitation on ASP MVC 2? I would really prefer to use a generic. The workaround that I have come up with is to change...

Generate a form from an untyped mvc 2 model or dictionary

HI all, I am looking for a way to generate and validate mvc 2 forms using untyped entities. Basically similar how the propertygrid in winforms behaves. In the utmost basic sample for instance have an dictionary and generate a form from that depending on the datatype in the Dictionary ofcourse it should be able to fill the same dictiona...

ASP.NET MVC 2: Custom client side validation rule for dropdowns

I have some custom validation that I need to perform that involves checking the selected option of a dropdown and flagging it as invalid should the user select a specific option. I am using ASP.NET MVC 2 and have a custom Validator and custom server side and client side validation rules as described in this blog article. The server side...

ASP.NET MVC 2: Dynamically enabling/disabling client side validation

Using MicrosoftMvcValidation.js for client side validation, is there an easy way of programatically (in javascript) turning the validation off and on for particular fields? Is it possible for example to use jquery to bind/unbind the events? ...

ASP.NET MVC2 Custom jQuery validation: client -side

Hi. I want to create a validation rule for 2 date-pickers (startDate less then endDate). I create a validation attribute: [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class DateCompareAttribute : ValidationAttribute { private const string _defaultErrorMessage = "'{0}' is less then '...

What is the best way to reset Ninject's IKernel container in an MVC app?

Basically in my Global.asax code I have the following IKernel property for Ninject setup like this (Also taking advantage of Microsoft.Practices.ServiceLocation). This Container is automatically called upon once it seems on the CreateKernel() override: protected override IKernel CreateKernel() { return Container; ...

Custom HTML attributes on SelectListItems in MVC2?

I have a need to add custom HTML attributes, specifically classes or styles to option tags in the selects generated by Html.DropDownFor(). I've been playing with it, and for the life of me I can't figure out what I need to do to get what I need working. Assuming I have a list of colors that I'm generating the dropdown for, where the op...

Querystring formatting in asp.net MVC 2

Seems like a straitforward question but I can't quite figure it out myself... I have an actionlink like so Html.ActionLink( "Test", "test", new { q = "search+twitter" } ) This produces a url string as follows http://myserver/test?q=search%2Btwitter But i would like to preserve the plus sign (which i assume is being UrlPathEncoded) ...

How to send link/url to confirm user registration and/or password reset/recovery using ASP.Net MVC2?

Hi, I see it all over the place, yet, I could not find one example about this (maybe I don't know the proper wording), I am trying to build using ASP .Net MVC2 (but any example on just ASP .Net would be also helpful) a process that will send a link to the user at the end of the registration process to let him confirm his registration. ...

MvcContrib Grid and Display/Edit Templates

Has anyone come across a good solution for using ./Views/Shared/DisplayTemplates and ./Views/Shared/EditTemplates with the MvcContrib.UI Grid? I guess I could wireup a CustomItemRenderer, but I would much rather be able to do something like: <% Html.Grid<Person>(Model.People) .Sort(new GridSortOptions {Column = Model.Column, D...

Limit JavaScript and CSS files on ASP.NET MVC 2 Master Page based on Model and View content

I want to include certain .js and .css files only on pages that need them. For example, my EditorTemplate DateTime.ascx needs files anytimec.js and anytimec.css. That template is applied whenever I use either the EditorFor or EditorForModel helper methods in a view for a model with a DateTime type value. My technique: I've put this c...

How to do some performance testing in asp.net mvc?

I am using asp.net mvc 2.0 and I want to test how long it takes to execute some of my code. In one scenario I do this load xml file up. validate xml file and deserailze. validate all rows in the xml file with more advanced validation that cannot be done in the schema validation. then I do a bulk insert. I want to measure how long st...