asp.net-mvc

Move Global.asax to iHttpModule when using ASP.NET MVC

I have successfully created an iHttpModule to replace my Global.asax file in many Web Forms applications. But in looking at the Global.asax file in my MVC application, the methods are totally different. I'm wondering if it is still possible to create this same thing in an MVC app. I know it's not necessary and the Global.asax works ju...

Separation of concerns and authentication

I'm trying to be a Good Developer and separate my concerns out. I've got an ASP.NET MVC project with all my web code, and a DAL project with all the model code. Sometimes code in the DAL needs to check if the current user is authorized to perform some actions, by checking something like CurrentUser.IsAdmin. For the web site, the curren...

Setting a profile property in asp.net MVC while creating a user.

In my application, an authorized user will Register a new customer and set their username and password, etc. The customer will not be registering them self. I have the following code in a class file which creates the new user, and it works just fine. public MembershipCreateStatus CreateUser(string userName, string password, string ...

Can someone explain this block of ASP.NET MVC code to me, please?

Hi folks, this is the current code in ASP.NET MVC2 (RTM) System.Web.Mvc.AuthorizeAttribute class :- public virtual void OnAuthorization(AuthorizationContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (this.AuthorizeCore(filterContext.HttpContext)) { ...

asp.net mvc routing

is there any way to find out to which route my url is getting mapped in asp.net mvc. ...

Visual Studio confused by server code inside javascript

I ran into an annoying problem: the following code gives a warning in Visual Studio. <script type="text/javascript"> var x = <%: ViewData["param"] %>; </script> The warning is "Expected expression". Visual Studio gets confused, and all the javascript code after that is giving tons of warnings. Granted, it's all warnings, and it works ...

ASP.NET MVC BaseController to dynamically set MasterPage file

I've built a Base Controller that all of my Controllers inherit from, and I've got it setup so that it checks the browser type and returns the appropriate MasterPageFile on the fly. I'm wondering if this is an efficient way to do this or if I should optimize it another way. Public Class BaseController : Inherits System.Web.Mvc.Controll...

ASP.NET MVC EnableClientValidation

Does this <% Html.EnableClientValidation(); %> really enable client validation that validation without page refresh or not? The thing is that it is doing a page refresh while returning formviewmodal ,it is working fine when using modal ? So how will i make it work using formviewmodal here is the code of the controller returning FormVie...

nhibernate : a different object with the same identifier value was already associated with the session: 2, of entity:

I am getting the following error when i tried and save my "Company" entity in my mvc application a different object with the same identifier value was already associated with the session: 2, of entity: I am using an IOC container private class EStoreDependencies : NinjectModule { public override void Load() { ...

Strang ASP.NET MVC behavior

i have a controlled called AppController. i have 2 actions: Details and Delete both pass in int id as the parameter to the action WHen i go to: mysite/App/Details/100 I can catch it in the controller details action but when i go to mysite/App/Delete/100 The breakpoint never hits and i get this in the browser: Server Error in '...

How do I add my SQL Server 2005 database to my VS MVC 2 project?

I want to use the built-in membership functionality that comes with the SQL Server Express database that is created when the project is built but I want to use it in my SQL Server database without having to re-create the wheel so to speak. ...

Access parent class from custom attribute

Hi, Is it possible to access a parent class from within an attribute. For example I would like to create a DropDownListAttribute which can be applied to a property of a viewmodel class in MVC and then create a drop down list from an editor template. I am following a similar line as Kazi Manzur Rashid here. He adds the collection of ca...

One repository per table or one per functional section?

I am using ASP.NET MVC 2 and C# with Entity Framework 4.0 to code against a normalised SQL Server database. A part of my database structure contains a table of entries with foreign keys relating to sub-tables containing drivers, cars, engines, chassis etc. I am following the Nerd Dinner tutorial which sets up a repository for dinners wh...

How to validate properties across Models without repeating the validation logic

Hello All, I am building a ASP.NET Mvc app. I have a Data model say User public class user { public int userId {get; private set}; public string FirstName {get; set;} } The validation to be done is that the firstname cannot exceed 50 characters. I have another presentation model in which i have the property FirstName too. I...

What's wrong with my HtmlHelper?

I've created an Html extension method in Helper class, but I can not get it to work. I've implemented it as seen on different tutorials. My MenuItemHelper static class: public static string MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName) { var currentControllerName = (string)help...

What is the difference between ASP.Net MVC and ASP.Net MVC2?

I've decided to take the suggestion from Robert Harvey on this site and build an application using ASP.Net MVC. When I went to Bing for a brief overview, I saw there was an MVC2. What is the difference and should I care? ...

Reload jQuery when returning partial view from a controller?

I am making the following call in my web page: <div id="comments"> <fieldset> <h4> Post your comment</h4> <% using (this.Ajax.BeginForm("CreateStoryComment", "Story", new { id = story.StoryId }, new AjaxOptions { UpdateTargetId = "comments", OnSuccess = "OnStoryCommentAdded" })) ...

Setting Response.StatusCode in View in ASP.NET MVC2

I've just converted a project from MVC1 to MVC2. In the MVC1 project the HTTP status code was being set in some of the views. These views are now generating this exception: Server cannot set status after HTTP headers have been sent. What has changed from MVC1 to MVC2 to cause this and is there any way to fix this? ...

How make data entry using autogenerated texboxes in ASP.NET MVC?

I'm asking a simple question on how to do data entry when using a custom number of textboxes. Usualy, in books, or tutorials, we consider a fixed number of entries for the controller. But what if the number of entries varies? For a concrete example, imagine some number of products which we need to enter quantity. How to manage this i...

Can I make ASP.NET MVC2 applications using an express version of Visual Studio?

I'm going to make an MVC2 application using C#. Which IDE can I use for free that will help me build this application? The different versions are very confusing to make out. I'm going to be following this tutorial: http://nerddinnerbook.s3.amazonaws.com/Part1.htm I see it makes use of Unit Testing. Can an express version do this? ...