asp.net-mvc-2

ASP.NET MVC: How to execute Data Annotation validations in the service layer?

In a recent question posed here: http://stackoverflow.com/questions/1558457/asp-net-mvc-is-data-annotation-validation-enough ...it was concluded that relying on data annotation validation (triggered by the model binder) was not enough to ensure that validation was always executed. We still need to add the same validation logic in the s...

ASP.NET MVC RequireHttps

How do I use the ASP.NET MVC 2 Preview 2 Futures RequireHttps attribute? I want to prevent unsecured HTTP requests from being sent to an action method. I want to automatically redirect to HTTPS. MSDN: RequireHttpsAttribute RequireHttpsAttribute Members RequireHttpsAttribute.HandleNonHttpsRequest Method How do I use this feature?...

Html.EditorFor SelectList

With introduction of Html.EditorFor all just seams easier. All but one thing: EditorFor< SelectList> What would be the best way to make it work? What I need is either a checkboxlist, a dropdownlist or the like. I can easily find mvc1 solution for the problem, but mvc2 seams not to be there. Any thoughts? ...

ASP.NET MVC 2 How are urls/routes, views related to controllers?

Could someone explain how routes are associated with controllers in MVC 2? Currently, I have a controller in /Controllers/HomeController.cs and a view /Home/Index.aspx. My route registration method looks like this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*path...

Deploying ASP.NET MVC 2 Preview 2 with Areas

We migrated from MVC 2 Preview 1 to MVC 2 Preview 2 to using multi-project areas. Everything works perfectly on local dev machine (Visual Studio 2008 SP1/IIS 7), however, it's does not work after I publish it to the server (Windows Server 2003/IIS 6). The deployment is done through the Build->Publish option in the VS2008 menu. I had als...

error running asp.net mvc 2 project out of the box in vs 2010

i created a new solution and it builds fine targeting framework 4.0 but when i run it, my browser comes up saying: The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following U...

ASP.NET MVC Custom View Engine Not Being Called.

I am attempting to impliment a custom view engine to serve mobile views based on the user agent. I am following Scott Hanselman's approach from this blog post. I have inherited from the WebFormsViewEngine and overridden the FindView method the same way that Scott describes in his blog. I then added a few lines to my Global.asax Applica...

MVC AreaRegistration

Where is Class AreaRegistration ?**strong text** Cannot find Class AreaRegistration in MVC 2 ? I Have installed MVC 2 Preview 2 (Had Preview 1 instlled but not used) using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcAreasSingleProject.Areas.Blog { public...

asp.net mvc 2 EditorFor() and html properties

Asp.Net MVC 2.0 preview builds provide helpers like Html.EditorFor(c => c.propertyname) If the property name is string, the above code renders a texbox. What if I want to pass in MaxLength and Size properties to the text box or my own css class property? Do I need to create one template for each size and length combinations in my a...

Routing and GetVirtualPath problem

I'm using MVC 2 Preview2, with two areas in a single project. When I use RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, null) from inside an area, I got the virtual path to the first area instead. Except for this, areas are working pretty well. What can I doing wrong? ...

ASP.NET MVC - controller action method from console application

I want to have an console application that I would use to render the output to a file. Pseudocode: ComponentBaseController controller = new ComponentBaseController(); SaveToFile("output.html", controller.Result); I am not using real code here since I have tried different approaches, but nothing gets me near. The closest I got using ...

Do DataAnnotations only work with EntityFramework/Linq2Sql Classes ?

Hi, Im using Preview 2 of the ASP .NET MVC Framework. Im trying out DataAnnotation attributes with my own NHibernate models but they dont seem to work. I was under the impression that the validation is supposed to get triggered by the model binding during a post. But even thou my model binds perfectly with wrong data supplied by me, t...

MVC Templated Helper - DropDown

Using the templated helpers in MVC2.0 I ran into a dillema, how to get the items to fill a dropdownlist. I am using a [UIHint(BadgesDropDown)] attribute, but how will i get the list items without violating the MVC Pattern, should the controller place them in the ViewData? Should the BadgesDropDown.ascx invoke a Helper to get them ? Righ...

How to unit test ModelBind with Data Annotation validation ?

I am working on asp.net mvc application using the mvc2 framework. Here is the view. <% using (Ajax.BeginForm("CreateMenuCategory", "Admin", new AjaxOptions { UpdateTargetId = "tabs-MenuCategories", })) { %> <fieldset class="fields"> <legend> Add Menu Categories ...

Exception when VS 2010 ASP.NET Development Server Serves Static Files

I'm building an ASP.NET MVC 2 site with Visual Studio 2010 Beta 2. Out of nowhere none of my images or css started showing up. If I navigate directly to the resources in the browser I see this exception message: Specified argument was out of the range of valid values. Parameter name: utcDate Stack Trace: [ArgumentOutOfR...

ASP.NET MVC: Hierarhical roles, custom authorization

Is there a way to organize the roles in my app like a tree? You know, User can do several things, Moderator is just like user but can do little more, Administator have even more abilitities, etc. I've found nothing in the "Web Site Administration Tool". ...

ASP.NET MVC ModelMetaData: Is there a way to set IsRequired based on the RequiredAttribute?

Brad Wilson posted a great blog series on ASP.NET MVC's new ModelMetaData: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html In it, he describes how the ModelMetaData class is now exposed in the Views and templated helpers. What I'd like to do is display an asterisk beside a form field label if...

ASP.NET MVC 2.0 JsonRequestBehavior Global Setting

ASP.NET MVC 2.0 will now, by default, throw an exception when an action attempts to return JSON in response to a GET request. I know this can be overridden on a method by method basis by using JsonRequestBehavior.AllowGet, but is it possible to set on a controller or higher basis (possibly the web.config)? Update: Per Levi's comment, th...

ASP.NET MVC2 Dynamic HTML

I have a discussion forum/blog engine working with web forms. Each post contains html entered within an editor that is stored as an nvarchar in SQL server. When I display this in a view, like so: <%#Eval("body")%> The eval function escapes the html, so I gt &lt, &gt, yada yada yada. Anyone know a good way around this? ...

ASP.net MVC v2 - Debugging Model Binding Issues - BUG?

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 ...