asp.net-mvc-2

How does one add an "id" attribute to Html.LabelFor() in ASP.NET MVC2?

How would one add an "id" attribute to Html.LabelFor() in ASP.NET MVC2? This is my label code: <%=Html.LabelFor(x => x.FirstName)%> This is my failed attempt: <%=Html.LabelFor(x => x.FirstName, new { @id = "first-name" } )%> Thanks. ...

DropDownListFor does not select value if using int[] as value

In my view <%= Html.DropDownListFor( x => x.Countries[ i ], Model.CountryList )%> in my controller public int[ ] Countries { get; set; } public List<SelectListItem> CountryList { get; set; } When the forms gets posted there is no problem, the dropdown is populated and the values the user selects are posted. But when I try to load ...

Why is IHttpAsyncHandler being called over IHttpHandler?

I made a custom handler that derives from MvcHandler. I have my routes using a custom RouteHandler that returns my new handler for GetHttpHandler(), and I override ProcessRequest() in my custom handler. The call to GetHttpHandler is triggering a breakpoint and my handler's constructor is definitely being called, but BeginProcessReques...

Architecture with NHibernate and Repositories

I've been reading up on MVC 2 and the recommended patterns, so far I've come to the conclusion (amongst much hair pulling and total confusion) that: Model - Is just a basic data container Repository - Provides data access Service - Provides business logic and acts as an API to the Controller The Controller talks to the Service, the S...

Repository Pattern and Entity Framework.

I want to make an implementation with repository pattern with ASP.NET MVC 2 and Entity Framework but I have had some issues in the process. First of all, I have 2 entities that has a relationship between them, like Order and Product. When I generate my dbml file it gaves me a class Order with a property that map a "ProductSet" and one ...

Is asp.net MVC2 included in .net 4.0 framework?

I've installed .net 4 in the server. Now I don't know if I must install the MVC 2 for VS2008 or what because I got this error: Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. ...

Link to resources such as css and javascript files

How can I link to resources such as css and javascript files? My default project is using links like ../../Content/styles.css. How can I do something like ~/content/styles.css? ...

Error in ASP.NET MVC 2 View after Upgrading from ASP.NET 4.0 RC to RTM

In my View, I am trying to loop through a list in a LINQ object that as part of my View Model. This worked fine earlier today with the VS2010 RC and the .NET 4.0 RC. <% if (Model.User.RoleList.Count > 0 ) { %> <% foreach (var role in Model.User.RoleList) { %> <%: role.Name %><br /> <% } %> <% } else { %> <em>None</...

Where does User.Identity data come from?

For example: if I am retrieving User.Identity.Name, does it come from .ASPXAUTH cookie or is retrieved from the database using my membership provider? Are any database requests made when I access User.Identity? Thanks. EDIT: Right now I am pretty sure it comes from an authentication ticket cookie, but can't find any official documen...

How to rewrite a path using a custom HttpHandler

I'm writing a multi-tenant app that will receive requests like http://www.tenant1.com/content/images/logo.gif and http://www.anothertenant.com/content/images/logo.gif. I want the requests to actually map to the folder location /content/tenant1/images/logo.gif and /content/anothertenant/images/logo.gif I'm using asp.net Mvc 2 so I'm sure...

Sample MS application for ASP.NET MVC?

I am getting started with my first MVC project and want to start off on the right foot. I know the basics of how to create a quick and dirty MVC application. However, I'd like to get my hands on a resource that uses best practices for developing ASP.NET MVC applications (either a document or a sample quickstart app) Any help is apprecia...

Where is the best place to reference javascripts in an XHTML document

I have an Asp.net MVC project that modestly uses jQuery scripts. My views also display partial views in them, either returned using RenderPartial or RenderAction helper methods. Partial views are usually used to encapsulate some common display but they may as well have some client-side script functionality. My javascripts have the same n...

Custom built ASP.NET MVC2 breaks the strongly-typed views

I have a problem with a custom built ASP.NET MVC2. The strongly-typed views break as the viewdata is treated as 'Object' instead of the corresponding type. The same views work perfectly with the default MVC2 from Microsoft. ...

Default Controller for an Area?

This is sort of a duplicate of http://stackoverflow.com/questions/2045761/trouble-setting-a-default-controller-in-mvc-2-rc-area But his answer doesn't satisfy me, because it doesn't work. I have the following /Areas/TestArea/Controllers/HelloController /Areas/TestArea/Views/Hello/Index /Controllers/HomeController /Views/Home/Index ...

ASP.NET MVC 2.0 Client-Side Validation HOWTO

Where can I find some good information on the new client-side validation functionality included in ASP.NET MVC v2? I'd like to find information about using the client-side validation JavaScript without using DataAnnotations, and I'd like to find out how custom validations are handled. For example, if I want to validate two fields toget...

ASP.NET MVC 2 + LINQ to SQL - CS0012 Compilation Error

Hi, In my database schema each forum has a category and categories can have many forums. I'm trying to list categories and their respective forums with the following code: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <asp:Content ID="Content1" ContentPlaceH...

ASP.NET 4.0 MVC2 routing on IIS 6

ASP.NET 4.0 MVC2 routing on IIS 6 is not working for me with all the methods used for 3.5 Works fine as long as I build in 3.5 but building in 4.0 and setting the server to use 4.0 I loose my routing. Anyone seen this and been able to resolve it? ...

Crystal report file does not get deployed to server in ASP.NET MVC

I am using a crystal reports through crystal report viewer server side control in a webform. I am using a webform because the crystal report viewer provides an easy way to export to PDF and to Excel. My problem is that when I deploy to the server, the crystal report .rpt file does not get copied to the target folder. My solution struc...

Binding View Model from a form post with inner complex types.

Ok, i got a viewmodel as follows: public class PageViewModel { public Item Item { get; set; } ... public PageViewModel { } public PageViewModel(Item itemWebPage) { ... } } I use a form to edit this Item using a route like: /Controller/Edit/43 The controller uses this code: [AcceptVerbs("GET")] p...

ASP.Net Authentication with MVC2--how to integrate with DB?

I'm trying to understand the authentication section of the sample project that opens in a new MVC2 project in VS2010. It essentially lets you register, login, etc. I looked through the code that implements this briefly, it looked fairly complicated. (10 tables, 40 sprocs, 10 views, 4 models, 1 model, 1 controller, etc.) Is it best to...