asp.net-mvc

Clean Way to Test ASP.NET MVC Controller Without Hitting Database?

I'm trying to think of a good way to clean up my controllers to make them more testable without having to rely on a constant database connection. I thought I had a decent start by abstracting away my object context with an IObjectContext. This works well for the context, but my next problem is that I have a generic repository that I use ...

Operator == cannot be applied to Guid or int in Linq (MVC book example)

Working through the WROX "Beginning ASP.NET MVC 1.0" book I've hit a strange 'error'. "Operator '==' cannot be applied to operands of type 'System.Guid' or 'int'". The line in questions is: (p => p.ID_Officers == id).Single(); The full code is below, and Officers is my table, ID_Officers is my ID field. (I imagine that I could of us...

Adding DataAnnotations to auto-generated DBML Class? MVC 2.0 ASP.NET

i'm worried about doing this since my changes will be overwritten when the dbml file is auto generated again (as they often are). i'm thinking of doing a partial class and writing out the same properties to annotate them, but worried that it will complain about duplicates, and the reason i can't even experiment brings me to the second p...

Determine the view count for specific page in Asp.net MVC

Hi, Do anyone knows how to do the View count for a specific page. Like in StackOverflow, in the question list you would see the View count which describes how many times the question was viewed. I would like to know how to do this in asp.net mvc. I already have an idea but im not sure if right. I need an expert advice... thanks ...

how to correctly identify vs2008 version level?

at SO, I searched "identify version visual studio" but failed to find an answer. Scenario: A generally accepted best practice is to install all service packs related to the software that one is using. The applies to Visual Studio 2008 too. In some cases, it is absolutely essential, for example VS2008 SP1 is required if one wants to i...

XSLT vs MVC vs CSS for flexible mobile/normal layouts

I'm building a new front end for an existing forum project, and I'm undecided on the best route to take for the user front end. The project will be built in ASP.Net 3.5. The requirements are as follows: 1) User selectable themes/templates must be supported - I have forum goers who will want to contribute forum themes, so the layout sys...

$.ajax post to MVC controller returns Internal Server Error: Parameters dictionary contains null entry

The parameters dictionary contains a null entry for parameter 'appId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ContentResult CheckForInstaller(Int32)' in 'HLIT_TicketingMVC.Controllers.TicketController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. functi...

Displaying ASP.NET Chart controls in ASP.NET MVC site with virtual path

I have a simple project that combines ASP.NET MVC with ASP.NET Charts control. Code is super simple and works IF I do not specify any "Virtual Path" when I run it in VS 2008. I followed Mike Ceranski post on his blog here: http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx But, if I put a virtual path (i...

can I make use of user.IsInRole without using Membership ?

I'm using Forms authentication and I would like to make use of roles, can I somehow set the role of the user without Membership ? ...

Help create a unit test for test response header, specifically Cache-Control, in determining if caching has been disable or not...

Scenario: I have a base controller which disables caching within the OnActionExecuting override. protected override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false)...

is it ok to use a key in Session for the current user's Role ?

Can I just use Session["role"] = "theRole", or that would be a bad practice, so I would create my custom authorize attribute where I'm going to look into the Session ...

ASP.NET MVC error page content inside JQuery populated DIV

I have a pagination control that refreshes a DIV via some JQuery Ajax, however if and when an error occurs say if the page crashes because it couldn't connect to the database or some other reason. My default error page gets displayed inside that DIV instead of the results.. So my question is how do you make it so that doesn't happen, th...

Speed difference between anonymous class and IDictionary<string,object> for htmlAttributes in ASP.NET MVC

I am trying to optimize my ASP.NET MVC application using some techniques that include URL generation tweaking a la: http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html If the speed difference is so large between using RouteValueDictionary in place of anonymous classes, then should I also look to u...

ASP.NET MVC for Ruby on Rails developers?

Long time lurker, first time poster. I'm a self-taught hacker that learned Ruby on Rails to start. At work I've been allowed to work on a web app--the only catch is I have to use ASP.NET. This technology choice is mandated, as much as I'd prefer to use Rails. There's dozens of "Rails for .NET/PHP/Java Developers" books and blog posts bu...

Why is all my content disappearing when I turn on client validation in ASP.NET MVC 2 RC2?

I am using the following partial to render the editor for the Create and Edit pages: PersonEditor.ascx <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProj.ViewModels.PersonEditorViewModel>" %> <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript" /> <script src="../../Scripts/MicrosoftMvcValidation....

Application service layer as static classes

In my ASP.NET MVC application, I have a project that contains all the business logic/service layer. This project interacts with my Database (Entity framework) which is located in a separate project. I wanted easy access to the service layer, so I created static classes in it so they can be referenced easily. For example, if I'm in my co...

Should Html.Encode be called when building ActionLinks in ASP.NET MVC

If the name of a link is pulled from the database, should you be calling the Html.Encode method to clean the name? For example: Html.ActionLink(Model.PersonFromDB.FirstName, "Action", "Controller", new RouteValueDictionary { { "id", Model.PersonFromDB.Id } }, null) or: ...

Bug? Client-side validation in ASP.NET MVC 2 causes ValidationSummary message to show even if there is no error

With client-side validation turned on in ASP.NET MVC 2 RC2, the validation summary message is visible even when I first load my Edit.aspx page. It does not show in bold red, however, just plain text. If I submit the form with an error, then the validation summary message turns bold red, and a list of errors appears below. Here is the co...

Linq randomly returns periodic null results.

I've got a linq query, which is admittedly pretty large. I can't identify where it is going wrong because it ONLY happens on the remote server and I don't have the access to debug it. But it is basically like this... This code lists all of the 'folders' that the current member can see. (Folders contain images.) if (members...

How To Call The RenderAction in my Html Helper?

im extending the htmlhelper. but it i cannot call the renderaction of it. using System.Text; using System.Web.Mvc; using System.Web.Mvc.Html; public static class ViewHelpers { public static string Text(this HtmlHelper htmlHelper, string name, object value, bool isEditMode) { htmlHelper.RenderAction(......