asp.net-mvc-2

asp mvc: database calls and caching, introducing a 4th entity?

Here's the architecture of my app: I have a data access layer in a seperate assembly, with a class containing methods such as List_XYZ, Insert_XYZ, Update_XYZ etc. All methods return or use objects from an object model I've created, which also resides in the data access layer assembly. Inside my mvc app, I've created views, controller...

Is there any way to re-use editor & display templates in asp mvc applications?

We're developing 3 asp mvc applications, all will require some of the same shared editor & display template views. Rather than copy/paste these across all 3 projects, is it possible somehow to put them in a shared component and reference them somehow in all applications? ...

Invaid cast exception, even when I have an implicit cast operator defined (in asp mvc app)

I have an mvc model class created and one of the properties is of type 'MyObject'. It also has a System.ComponentModel.DataAnnotations.StringLength attribute on it. MyObject as implicit cast operators so it can essentially be used as a string: public static implicit operator string(MyObject o){...} public static implicit operator MyOb...

ASP.NET MVC 2 RC client side validation not working

I can't seem to get any client side validation working on a MVC 2 RC app. My model has the following: public class ExampleModel { [Required(ErrorMessage="Test1 is required")] [DisplayName("Test1")] public string Test1 { get; set; } [Required(ErrorMessage="Test2 is required")] [DisplayName("Test2")] public strin...

Server side validation in asp mvc 2, can the error message be moved to the vew?

I've just started getting into validation in asp mvc 2, and so far have been implementing server side validation through the System.ComponentModel.DataAnnotations attributes in the model. I agree, the correct place to put constraints is in the model, but is there any way to move the actual error messages into the view instead? ...

ASP.NET MVC 1 or MVC 2

I recently recieved the ASP.NET MVC 1.0 Professional book by Wrox, and in the intervening time, I found out that ASP.NET MVC 2.0 is being released soon. Questions Should I MVC 2.0? Are there any resources specifically for MVC 2.0? Should I learn MVC 1 and then unlearn concepts and then learn MVC 2? ...

ASP.Net MVC2: ModelState is invalid, but I don't know why

I'm using MVC2 with data annotations for validation on my page. I require a name and a valid birth date to be present. I'm providing both, and I break into the date validator to ensure that the birth date is valid (and it is), but for some reason Model.IsValid is false in my post action. I'm not seeing anything in my ValidationSummary. ...

Migrate from .NET MVC 1 to MVC 2 RC

Hi All, I've migrated a MVC1 project to MVC2 RC, and now the site doesn't work at all. I get the error "Entry point was not found." I migrated the project following this link I'm using Castle Windsor as DI. Here is a part of global.asax.cs public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{...

asp mvc design question: single view for multiple data types

In my database, there are maybe a dozen tables that represent lookup types (All have ID and Name columns - No, they must remain as seperate tables, won't be normalized into one table). I'm building an administration application, where I want an administrator to be able to add/edit/delete/list all of these lookups. I know I can re-use t...

EditTemplates and related objects with MVC2

I am learning MVC using the v2 release with Entity Framework v4. Let’s say I have 3 objects Game, Points and Players. They are related in the following manner: Game has points and the Points can have a player associated with them ( 1 Game to many Points and a Point object can have one Player). I am attempting to use the EditTemplates...

Contextual/RunWhen validation in ASP.NET MVC 2?

Does the latest ASP.NET MVC 2 validation allow contextual validation? I'm looking for something similar to Castle Validator's "RunWhen" property. It allows you to declare that a validator should only be executed in a particular context. The most obvious use is for Identity fields. The following would specify that the int ID field is ...

A potentially dangerous Request.Form value in MVC 2 & ASP.NET 4.0

When I trying to send form containing value with xml, I get HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client All approaches I found: <%@ Page ValidateRequest="false" %> in .aspx-file. <pages validateRequest="false" /> in web.config. [ValidateInput(false)] on controller's action...

Using a dynamic list of checkboxes in a view, how to create the model

I have an asp mvc 2 app lication where I want to display a list of check boxes that a user can select, based on a list of records in a database. To display the list my model contains a List object and the view has a foreach, and outputs Html.CheckBox for each item in the list. Is there a way to get the model populated with the select...

Unit Testing TryUpdateModel in MVC 2 RC awkward behavior

Before using MVC 2 RC I was using MVC 1, the code I used to update my object in my controller was this: TryUpdateModel(entity, null, null, new[] { "Name", "Controller" }); I was able to Unit Test this controller action just using this in my test: controller.ValueProvider = myFormCollection.ToValueProvider(); After migrating my code...

DataAnnotation Validations and Custom ModelBinder

I've been running some experiments with ASP.NET MVC2 and have run into an interesting problem. I'd like to define an interface around the objects that will be used as Models in the MVC app. Additionally, I'd like to take advantage of the new DataAnnotation functionally by marking up the members of this interface with validation attribut...

MVC2: How can I read control values for an action link?

I'm passing in some model information to an ActionLink, but I'd also like to provide the action with the values of some inputs on the page. For example, if I had something like this: <input Name="MyInput" /> <%: Html.ActionLink("MyAction", "MyController", Model.Value); I'd like the action to be aware of both Model.Value (which is pas...

ASP.NET MVC 2 DataAnnotations: No validation for incomplete AJAX POSTs

I have an entity model User and it's metadata is public class UserMetadata { [Required] [RegularExpression("...")] public String Username { get; set; } [Required] public String Password { get; set; } } I have a controller that recives REST callbacks. One of it's actions is // POST /users [HttpPost] [ActionName("...

How to specify an area name in an action link?

I have a shared master page which I am using from 2 different areas in my mvc 2 app. The master page has an action link which currently specifies the controller and action, but of course the link doesn't work if I'm in the wrong area. I see no overload for actionlink that takes an area parameter, is it possible to do? ...

Would you use MVC 2 already or MVC 1? - S#arp Architectur + Spark View Engine

I am starting to develop a complex web application using S#arp Architectur and the Spark View Engine. By default MVC 1.0 is used. But i am thinking about upgrading everything to ASP.NET MVC 2. Would u start developing in MVC 1 and upgrade to version 2 later or do the upgrade straight from the beginning? Thanks for your advice, -Ben...

How to write custom client-side jQuery validation in ASP.NET MVC 2 RC?

I've read Phil Haack's post on custom client-side validation in ASP.NET MVC 2. I want to do the same thing but with the jQuery adapter and using ASP.NET MVC 2 RC (as opposed to MVC 2 Beta that the post uses). Has anyone been able to figure how to do this? I specially want to implement the password matching validation (i.e. password & ...