asp.net-mvc-2

Viewless controllers?

Hi, I'm using ASP.NET MVC and I have a model class which represents a peice of data which is associated to an entity but created by another. For example, given the following ViewModels, public class User { public int UserId { get; set; } public IEnumerable<NewsComment> Comments { get; set; } } public class News { public int ...

ASP.NET MVC (2) NormalizeUrl Action Filter Attribute (C#)

Hi All, Can someone verify the integrity of this chunk of code? I want to decorate the controllers with it so that it will normalize the url to either https and/or www. This is my second rewrite of the code because the first one tossed itself into an infinite redirect, but somehow I still think it's not quite there... public class Norm...

Delete an object with a many to many relationship from the entities framework?

I have two objects (class, student) in a database with a many to many relationship (using a simple junction table). I've figured out how to correctly add new objects to tables, and now I'd like to delete an object. I've been trying the following: // (a classobj with id==1 does exist) ClassObj cl = (from c in entities.ClassObjs where c....

EF4 STE's and MVC2 - ChangeTracker not POSTing

I'm trying to set up an MVC2 app with Entity Framework Self-Tracking-Entities. My view is a strongly-typed view of the entity type generated by the STE T4 template. Here's my GET: public ActionResult Edit(int id) { var ri = new App1Service.App1Client().GetMyObj(id); var changeTracking = ri.ChangeTracker.ChangeT...

asp.net map route with parameter inside controller and view

I need to create a url scheme like this friend/{userid}/wishlist where friend is the controller, wishlist is the view, and userid is the id of hte friend whose wishlist you would like to see. I have setup a route like this routes.MapRoute( "FriendWishlist", "friend/{userid}/wishlist", new { contr...

What is the "Func<object> modelAccessor" parameter for in MVC's DataAnnotationsModelMetadataProvider?

It's one of the parameters supplied to the CreateMetadata method (which you override if extending metadata support). ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, <<--THIS ONE Type mo...

ASP.NET-MVC2: Why does TryUpdateModel ignore properties after the second level of the object model tree?

Perhaps I'm missing something here, but it seems that anything in the object model tree 3 or more levels down, is ignored when using TryUpdateModel. For example (simplified): public virtual ActionResult SomeAction(int id, FormCollection form) { IValueProvider vpFrom = form.ToValueProvider(); /* At this stag...

How to store ASP.NET masterpage data in application cache for set duration

Hi, I've been reading 'ASP.NET-MVC Tutorials' to learn how to generate data for the 'masterpage' view in an ASP.NET MVC application. It suggests the pattern of using a 'base-controller' and generating the data in its constructor. My issue is that I wish to store the application data in the application cache rather than the viewdata ...

ASP.NET MVC strongly typed helpers generate wrong input nam when are used inside foreach

Hi guys, I've got a problem with ASP.NET mvc stongly typed helpers. Here is example of wrong behavior: <% foreach (var item in Model) { %> <%: Html.TextboxFor(m => item.Name) %> <% } %> will generate following inputs: <input name="item.Name"..... As you see generated name is wrong, because of wrong algorithm of extracting proper...

Nhibernate/MVC: Dealing with lazy loaded collections in View

I'm currently using an attribute based approach to nhibernate session management, which means that the session is open for the duration of the Action method, but is closed once control is passed to the View. This seems like good practice to me, however I'm running in to problems with lazy loaded collections. (This is complicated by th...

Entity framework 4 - Base entity mapping 2 tables as base class for 2 derived entities possible?

I have the following scenario that is causing me problems around the mapping fragments referring to same Id columns. This is what im trying to achieve not sure its even possible! Essentially I want to have a common way of accessing content, and as needed a specialisation of blog and article. I have the Contents entity working with the...

How to dynamically group a list depending on role in asp.net mvc.

Here is my scenario: We would like to have a page listing donors, depending on the user viewing the page we would like to group by the donor's giving level, or just their sort name. The twist that is throwing me is that we would like to group the Anonomous Donors and give a count based on the grouping. In my controller I have [Http...

Use a different controller's action for the Index action of the Home Controller

I think this is a pretty common scenario, but I haven't been able to phrase my problem in such a way that I have generated any useful search engine results. I'd like the Index action of my HomeController to return the action from a different controller. I have come up with a few solutions but have dismissed each for various reasons: U...

Can an ASP.NET MVC2 site have an optional enum route parameter? If so, can we default that value if not provided?

Hi folks, can I have a route like... routes.MapRoute( "Boundaries-Show", "Boundaries", new { controller = "Boundaries", action = "Show", locationType = UrlParameter.Optional }); Where the action method is... [HttpGet] public ActionResult Show(int? aaa, int? bbb, LocationType locati...

Iframe makes 2 calls to Action instead of 1?

Hello, I have a website project in ASP.NET MVC2 and use a Fancybox which loads a contactform in an IFrame. It all works fine. But... When I debug my project in VS2010, the Action in my Controller got hit 2 times while I expected it to be hit only once. The Action gets hit by this Javascript code: $('<iframe id="fancybox-frame" name="f...

Autofac 2.2 and ASP.NET MVC 2.0 Areas support

Hi there! In his blog Nicholas announced support for ASP.NET MVC 2.0 Areas. However, I couldn't get it working and from what I see in Autofac sourcecode, areas support is nowhere to be seen. More specifically, RegisterControllers return builder.RegisterAssemblyTypes(controllerAssemblies) .Where(t => typeof(IController).IsAssignable...

Web Based Document Viewer Including Office Formats

I am looking for a web based way of showing users tiff, pdf, doc(x), and xls(x) files. This is being required from a business standpoint and I don't have a whole lot of weight/control into the decision being made. The web application will be used by both internal and external customers, not publically available though. Pricing is not su...

ASP.Net MVC 2 - jQuery Validation and Form Submit - DataAnnotations

I have a sample application, trying to learn jQuery validation and submit form in this scenerio. The page has one text box (EnvelopeID per class Envelope). If submit button is clicked and the text box is empty then i want to show an error message. If it is not empty then i want to post ajax request to GetData Action. The action returns...

ioc - castle windsor in asp.net mvc 2 + data context + connection string

I'm using castle windsor in asp.net mvc 2, with a separate project for the domain model which contains datacontext (dbml), I've deleted the app.config in the domainmodel project getting the following error: Can't create component 'DomainModel.Concrete.ArticleRepository' as it has dependencies to be satisfied. DomainModel.Concrete.Arti...

What is the fastest way to convert an Object type

I have a class that returns an object type to a variable. The variable Must know what the real type is when operations are performed on it: public object Data { get { switch (CriteriaID) { case (int)matrix2.enums.NodeTypeEnums.Enums.MultiLineText: return (s...