asp.net-mvc

Architecture abstraction problem in Repository ASP.NET MVC

Hi. I'm working with MVC ASP.NET 3.5 SP1 on VS2008. I'm looking for a way to abstract this three methods I have in my Users repository. public User GetUser(Log log) { return db.Users.FirstOrDefault(u => u.Logs.Any(l => l.id.Equals(log.id))); } public User GetUser(Product product) { return db.Users.FirstOrDefault(u => u.Products.Any...

Understanding how VS parses CSS in .ascx docs

I have a number of documents (in an MVC app) that exist solely to be called by: <% Html.RenderPartial("showLoginStatus"); %> While editing the file in VS (08) the CSS class selectors used within this page all toss 'class not defined' warnings since the stylesheet isn't referenced in this file but in the 'parent'. The page renders cor...

mvc route problem - using integer parameters

I have a route like this in my global.asax.cs: routes.MapRoute( "NewsArticles", "News/{page}", new { controller = "News", action = "Index", archive = false } ); How can I restrict access to this route so that it's only encountered if the user uses an integer? ...

Using DataAnnotations on Windows Forms project

I recently used ASP.Net MVC with DataAnnotations and was thinking of using the same approach for a Forms project but I'm not sure how to go about it. I have set my attributes but they do not seem to get checked when I click Save. UPDATE: I have used Steve Sanderson's approach which will check for attributes on my class and return a col...

Question on how to create WCF silverlight 3 endpoints.

I wanted to consume a WCF service with a silverlight application and a asp.net mvc application, and I'm having difficulties to configure the service to support both requests. these are my endpoints for the WCF config file. <service behaviorConfiguration="behaviorAction" name="Uniarchitecture.ProdutoService.ServiceImplementations.Prod...

I'm getting a "Does not implement IController" error on images and robots.txt in MVC2

I'm getting a strange error on my webserver for seemingly every file but the .aspx files. Here is an example. Just replace '/robots.txt' with any .jpg name or .gif or whatever and you'll get the idea: The controller for path '/robots.txt' was not found or does not implement IController. I'm sure it's something to do with how I...

How to turn output caching off for authenticated users in ASP.NET MVC?

I have an ASP.NET MVC application. I need to cache some actions (pages) however for some pages I need do such only for non authenticated users. I've tried to user VaryByCustom="user" with following GetVaryByCustomString implementation. public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom == "u...

mvc - file upload in external class

Hi, Im using scott hanselmans file upload code: public ActionResult UploadFiles() { var r = new List(); foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; string savedFileName = Path.Combine( AppDo...

MVC2: "File not found" after view is painted

This is wierd. First, I'm building a site based on someone else's framework (Piers Lawson: Creating a RESTful Web Service using MVC ), so I'm not entirely sure what's going on under the covers. But when I run it in VS 2010 by pressing F5, it brings up the Home page, and THEN traps an error in Application_Error. The error is "File does...

How to unit test the DataAnnotationsModelBinder in ASP.NET MVC 2

I'm using ASP.NET MVC 2 with DataAnnotation attributes sprinkled on properties like so: public class LogOnViewModel { [Required] public string UserName { get; set; } [Required] public string Password { get; set; } [Required] public string Domain { get; set; } } I have a unit test which checks that the curre...

ASP.Net MVC Get Area Name.

Hi, Given a Controller name, and a Action name - "AdminController", "Index" for example, is it possible for me to get back all the possible Areas. Does that make any sense to anyone? Cheer, ETFairfax. ...

Passing Objects from Views/Javascript to MVC Action

I am using MVC. I have a view model which contains a Business object. I need to post this Business Object back to a controller action using AJAX. For now, I am using Url.Action function to create my request Url for AJAX and pass the Business Object id as a request parameter to the action. I then have to retrieve the object from the dat...

MVC view can't find my extension method

I've created an extension method: namespace MyComp.Web.MVC.Html { public static class LinkExtensions { public static MvcHtmlString ActionImageLink(this HtmlHelper htmlHelper, string linkText, string imageSource, string actionName) { ... } } } I've referenced the assembly from my mvc app,...

ASP.NET MVC : Create an ambient value.

I have a simple web-site. Almost every action takes int toonId as an argument (toonId does not equate to the user: one user can own multiple toons). At the moment I provide that value to every view from controller, and every link and submit button sends this value back to the controller. This works. I am just looking for an easier way to...

ASP.NET MVC Default Project Structure and the Scripts Folder

Is there any advantage to leaving the Scripts folder where it is in the default ASP.NET MVC Project structure. In my mind it makes more sense to create subfolders for scripts, css files, and images under the Content folder. Any downside to doing this? ...

How to validate xml code file though .NET? + How would I do it if I use XML serialization?

I want users to be able to export data as an XML file. Of course I want them to be able to later on import that same XML file however they always could change it or it could be a different XML file. So I want to validate the XML file to check if it is in the format that I expect. So I guess I would need something like a schema to check ...

How can I tell what page I am on in a ASP.NET MVC application

I'm trying to get a good idea on how to modify certain parts of the page based on what page I'm looking at. I can set certain elements with the page's controller but I'm thinking more about the global navigation menu's (currently being rendered with a RenderAction in the application's MasterPage) active states. Like if I have some navi...

How to know Which version of MVC installed ?

How would I know which version of MVC (i.e 2.beta, 2.Release candidate) is installed on my machine.. ...

IPrincipal or Membership to retrieve username

What is the difference when retrieving username for the view? <%= Page.User.Identity.Name %> or <%= Membership.GetUser().UserName %> ...

MVC content cut off resulting in blank page

I have the strangest problem that I simply cannot solve by myself. I have this ASP.NET MVC 1 application that works flawelessly on my local development machine, using IIS5. I made the appropriate changes to get MVC to work on IIS5 by adding a route for .mvc controllers and an aspnet_isapi.dll filter as documented in http://haacked.com/...