asp.net-mvc

Fancy client-side form validation in ASP.net MVC2

It appears that the jQuery-based version of ASP.NET MVC2 form validation didn't make it into the final release. This is a bit unfortunate. First off, I can't figure out whether the version that did make it into the final release has an extension point - akin to an "onvalidate" event to which I can attach my own code... For instance, I w...

Automated testing with PHP

I'm a .net developer so pardon me for not knowing anything about PHP. I read some things on the net but I can't say how it compares to Asp.net MVC in terms of automated testing. I tend to think that PHP is very much like classic ASP except that it's OOP (is it?). In order to improve its testability you have to follow certain development...

return Json error from ASP.NET MVC

I'm trying to return an error message via Json from ASP.NET MVC controller. I want to display carriage returns on the screen, so the error will look like: Error 1. Error 2. instead of "Error1.\u003cbr/\u003eErro2.\u003cbr.\u003e" Here's my ASP.NET MVC code Response.StatusCode = (int)HttpStatusCode.BadRequest; string str = "Error 1...

Get instance of ActionFilterAttribute in the method

I am newbie in ASP.NET MVC platform and I faced with the following problem. I am using ActionFilterAttribute to do some routine work before and after action method run. The problems is that I need to get instance of the attribute in action method to read some properties which was set in OnActionExecuting method. For example public cl...

Accounting for the length of an HTML DIV for truncating text

I have a <div> that I'm filling with a file name of indeterminable size. If the size exceeds the length of the <div> then I want it to be cut down and the last 3 characters replaced with a "...". Currently I have the following: <div id="fileName" class="field-row" title="<%= fileName %>"> <% if(fileName.Length > 20) { %> F...

Does it make sense to set Http Cache Headers on a 404 response?

I have a database that stores images which can be access via a primary key ID (vomit, I know, but it's out of my control). I have a pretty standard Asp .net Mvc Controller that reads the database and if a row is found in the database it returns the image bytes as a FileResult. If a row is not found, I have a custom action result that se...

mvc url rewriting....

so write now my Url looks like domain.com\MyAction?var1=x&var2=y&var3=z. Now, in order to make it more seo and user friendly, I want to abandon that way of writing and adopt this kind of url - doman.com\MyAction\x\y\z (obviously order matters now, which didn't matter in the previous url) What is the best way to do this? Currently: ...

windows server 2008 IIS 7.5 maximum file accept limit

I have deployed my application on IIS 7.5 on windows server 2008 operating system and i want to know what is the maximum file upload limit and how to increase that limit? Im working on asp.net mvc2 ...

How to manage custom fonts in web application (system.drawing)

I have an application that writes text onto images using system.drawing (C#). I am using specific fonts to do this. Since I can't rely on my shared hosting servers to have all the custom fonts I may need (and since the list of fonts is likely to grow), how can I manage the fonts used for my application? Could I include .ttf files in m...

jQuery / asp.net-mvc: How can I display Hierarchical Data using IHierarchicalEnumerable?

I have an asp.net backend that creates Hierarchical Data based on IHierarchicalEnumerable. This was used for custom Hierarchical Data Controls in ASP.NET WebForms for sitemaps etc. We are now using ASP.NET MVC and am looking to use the same Hierarchical Data Collection with jQuery / Json etc. How can I display Hierarchical Data using ...

ASP.NET MVC navigation route that changes based on viewed data

I am in the process of creating tabbed navigation where the route location can vary. The parameter used to render the tabs should be based on the presently viewed data (which when it is a user, may not be the logged in user). In the example image this is a user. Therefore, if I am looking at Andrew Steele then the links should be contex...

asp.net mvc - category/1 to category/fruit... right approach?

suppose I have 3 categories 1, 2, 3 named fruit, vegetable and grain. Right now I have domain.com/category/1 which would take me to fruit's page and so on... Now I would like to domain.com/category/fruit to take me to fruit's page because that looks nicer and categories are very few like 3 or 4 max... so I don't plan on looking at dat...

Delete Issues with Nhibernate

I have two Classes. "Product" and Product can have a number of objects of class "Attribute" When someone edits the "Product" I would like to delete all Attributes associated with that product and recreate the new ones (second part works fine) but I'm getting a error which stops me removing the attributes. public ProductMapping() {...

Naming resource strings in .NET apps

How do you usually name localizable resource strings in your RESX files? I used to do it manually, taking special care about resource naming and usually end up with something along these lines UsernamePasswordLogonFailure But with the new Resharper there is a functionality that detects and picks up string literals in code and gives yo...

DTO shape: flat, complex/nested, or a mixture of both

I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD approach (Domain Driven Design), having a Domain Model with repositories. My service layer uses a Request/Response pattern, in which the Request and Response objects contain DTO's (Data Transfer Objects) to marshal data from one layer to the next, and the mapp...

How to serve up image from type System.Drawing.Bitmap (<img> tag?)

I am sending a bitmap to a View in ASP.NET MVC. I have a property in my ViewModel: public Bitmap TemplateImage { get; set; } In my View, I want to be able to render that Bitmap image but I can't figure out how to do it. ...

Web app NHibernate Session Management Summer of NHibernate style

I'm writing a web app using ASP.NET MVC 2 and picked NHibernate as my ORM. I basically learned my basics from watching the Summer of NHibernate series, and have adopted the authors session per request strategy for managing a session (Ep 13). Things seem to work well, but I'm concerned about whether this is a functional real world appro...

Using Url.Content in ASP.net MVC 2.0

I've seen a lot of examples using Url.Content to reference javascript, form MasterPages in MVC 2. <script src="<%: Url.Content("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript"></script> But on runtime I've got failure, Compilation Error Description: An error occurred during the compilation of a resource required ...

How to specify order of Data Annotation errors in Html.ValidationSummary

I'm displaying errors on my form with the use of <%= Html.ValidationSummary("Please review the errors below") %> My domain object inherits from a base class and I am finding that the base class data annotation properties are being displayed at the bottom of the list. This goes against the order in which they appear in my form. Is the...

Is there any need to use Html.Encode for an internal site?

I'm having some problems with Html.Encode and users wanting to use special characters. Firstly the characters are replaced by the html codes and so are not displayed properly. And then, if the text is later edited and re-submitted, an exception is thrown when these html codes are re-submitted. Given that this is an intranet site and the...