asp.net-mvc

asp.net mvc Html.ActionLink() keeping route value I don't want

I have the following ActionLink in my view <%= Html.ActionLink("LinkText", "Action", "Controller"); %> and it creates the following URL http://mywebsite.com/Controller/Action Say I add an ID at the end like so: http://mywebsite.com/Controller/Action/53 and navigate to the page. On this page I have the markup I specified above. Now wh...

ASP.NET MVC Roles Authorization

I want to make the roles default for my controller class to "Administrators, Content Editors" [Authorize(Roles = "Administrators, Content Editor")] I've done this by adorning the controller with the attribute above. However, there is one action that I want to be available to all (namely "View"). How can I reset the Roles so that ever...

Conditionally displaying parts of my view

Say I have an asp.net mvc website with a page that lists products. ON that page I have a "delete" button that should only show up for the user that inserted the product. What's the best way to do this? One way I thought of doing it was setting a boolean in the controller to let the view know if the button should be displayed. Something ...

ASP.NET MVC Page Editing Contrast To Web Forms

In our old system we had pages rendered from XSLT. In order to change the page into "edit" mode we would have a button of some sort, once clicked would have an EditYN flag which would be passed to the stored procedure. The stored procedure would simply give this variable back to indicate that the page was in edit mode. This meant that...

asp.net mvc DataAnnotation Validation

Hi, i going to create some validation for custom object in my app. But i have some trouble when try to create CustomValidation rule. My object has field - BirthDay - which not required but if user enter it i need to validate it on simple validation, for example user DataType validation - DataType.DateTime. When i am try to do it i have v...

Why doesn't switching to release in VS set the debug parameter to false in web.config

In VS2008 (and earlier if I'm not mistaking) I have dropdown that lets me choose between Debug and Release mode. All well. When I switch VS to Release, the debug attribute in my web.config files isn't set to false at all though. Is this the way it is supposed to be? I am bound to forget to set it to the correct value on deploying.. What ...

ASP.NET MVC - jQuery Sortable

I have a list of menu items which can be sorted. I have the sort working which is based on this link. However, I'm not sure how to save the order of the menu items to the database? I'm using nhibernate. View Code <h3>Sort Main Menus</h3> <% using(Html.BeginForm()) { %> <p>You can drag the items into a different order</p> <p></...

ASP.NET MVC Function Calls

I've got a master page which has a function in it called GetSiteMap(), this function is used to custom render a sitemap based on the current location. My problem is that in MVC you don't have the code behind model thus not exposing that kind of functionality. What's the correct way to do it? Should I have a master page controller of s...

Large data entry pages using ASP.NET MVC

I am working on a large data entry page using the default ASP.NET MVC theme. Due to the large number of controls on the page it would be good to use a two column fieldset so the user does not need to scroll. I can't see any templates in the MVC design gallery that use a two column data entry page, they are all geared towards standard web...

How do I make this ASP.NET MVC Route for a twitter-style URL work?

Hi all, trying to map the following style of route: http://site.com/username in the same way that you can do http://www.twitter.com/user My initial solution was to have these routes: //site.com/rathboma - maps to user details for rathboma routes.MapRoute("Users", "{id}", new { controller = "Users", action = "Details" }); ...

Puzzled about the ASP.NET MVC DefaultControllerFactory.cs Implementation

While investigating implementing my own IControllerFactory I looked into the the default implementation DefaultControllerFactory and was surprised to see the RequestContext property being set in the CreateController(...) method, and then being referenced in the GetControllerInstance(...) and GetControllerType(...) methods. The reason fo...

Thickbox modal form related

I am using asp.net MVC. I am opening my login page as Modal page Like this -> Login demo The problem is when user gives incorrect information then I lost parent page. And this happens because the errors comes with another page and it removes parent page. So how to update the modal page? I know ajax update is possible so don't give ...

How can I get this ASP.NET MVC SelectList to work?

Hi folks, I create a selectList in my controller, to display in the view. I'm trying to create it on the fly, sorta thing .. like this... myViewData.PageOptionsDropDown = new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15"); It compiles, but the output is bad... <select id="PageOptionsDropDown" name="PageOptio...

ASP.NET MVC - different models for master page and view page

I have a strongly typed master page, but I want to use a different type for some of it's child pages. For example, on the master page... <%@ Master ... Inherits="System.Web.Mvc.ViewMasterPage<MyWeb.Models.Client>" %> Client is already a composite object, so on some of the child pages I can keep to the same model and just reference me...

Execute some specific code before member functions of a class using attributes?

I have a class: public class MyClass { public int code { set; get; } public bool foo() { // do some stuff // ... code = 100; return true; } public bool bar() { // do some stuff // ... code = 200; return true; } // more methods ... // ... } I would like to reset the value of code to z...

How do you change the controller text in an ASP.NET MVC URL?

I was recently asked to modify a small asp.net mvc application such that the controler name in the urls contained dashes. For example, where I created a controller named ContactUs with a View named Index and Sent the urls would be http://example.com/ContactUs and http://example.com/ContactUs/Sent. The person who asked me to make the chan...

ASP.NET MVC Tutorials using SQLServer?

How can I use SQLServer (instead of SQL Express) as my database? I'm trying to go thru the ContactManager tutorial, but I can't seem to get it to use SQLServer - when I pick SQLServer from the "Add New Item" dialog, I get an error telling me that SQL Express isn't installed. I know I must be missing something basic... ...

How do you mock the caching object in asp.net mvc?

How would I mock the caching object on the ControllerContext object for my unit tests? I have tried creating a wrapper class like the following (since the cache object is a sealed class) with no luck. var mockControllerContext = new Mock<ControllerContext>(); var mockhttpContext = new Mock<HttpContextBase>(); mockhttpConte...

Unit of work/repository managers for NHibernate?

I'm a .NET developer by day, but have been working with Rails and Merb for the past year on my own side projects, so when it comes to MVC and ORMs, I'm more used to them and using ActiveRecord and DataMapper. I'm getting started with ASP.NET MVC, and I like what I see in NHibernate and Fluent NHibernate, but looking for a little bit mor...

ASP.NET MVC View Post-Processing

In Monorail there's a transform filter concept, where a rendered view can then have further processing applied to it. Use cases: Process markdown Remove whitespace Strip unwanted characters I suspect there is no out-of-the-box method of doing this in ASP.NET MVC but does anyone have a suggested approach? I'm using the NVelocity view ...