asp.net-mvc

How do I route the default debug path to the actual path in asp.net mvc?

When I click run on my vs2008 to try out a page it tries to load http://localhost:14092/Views/Employee/Index.aspx which should be http://localhost:14092/Employee/Index or http://localhost:14092/ How do I add these 2 routes? (I want to know how to do both so I can swap them as desired. Here's my current routing code: public stati...

Is it possible to use the 'using' statement in my aspx views? (ASP.NET MVC)

This likely applies to non MVC too. But, Is it possible to use the 'using' statement in my aspx views? Reason is that I have the pages reference resource files for localised strings. And some of these resource references are quite long - it's really cluttering my code. Since most of the time these resources are in a namespace specifi...

Can you render a partial result in a controller?

Hi I am wondering is there a way to render a partial view in the controller. So like you have a partial view and instead of returning it you render it right there in that controller method and store the result into a string or something like that? ...

url paths for resources

Hi , i am a newbie on web development, so i have some problems first of all what is the meaning of ~, / on an url? My real question in my javascript code i am doing some ajax calls with jquery like that $.ajax({ ... url: '/Membership/Login', ... }); There is an Membership controller with an Login action method that i need to s...

Best practices to convert a NHibernate app as multi-tenant?

I have a simple ASP.NET MVC + OpenID + NHibernate app (on top of MSSQL Server DB). The app is strictly single tenant and supports multiple users with only 2 roles (Admin and User). I would like to convert this app into a multi-tenant app. My requirements are limited: I just need to introduce the notion of Accounts, each account having i...

How to remove an object from a list collection?

Hi I had to change on my lines of code around. I before had something like this // this is in a static method. List<string> mySTring = new List<string>(); mySTring.add("one"); mySTring.add("two"); However on one of my pages I have a dropdownlist that does not require the field "two" so instead of writing duplicate code all I did was...

How to sort an ASp.net MVC dropdownlist?

Hi I have this code List<SelectListItem> list = new List<SelectListItem>() { new SelectListItem() { Text = "bob", Value = "bob"}, new SelectListItem() { Text = "apple", Value = "apple"}, new SelectListItem() { Text = "grapes", Value = "grapes"}, }; This will be used for binding with the asp.net mv...

Redirect a user to a specific view when authorization fails?

I have the following code: [AcceptVerbs(HttpVerbs.Post), Authorize(Roles = RoleKeys.Administrators)] public ActionResult Edit(int id, FormCollection collection) { User user = userRepository.GetUser(id); try { this.UpdateModel(user); userRepository.Save(); return ...

How can I convert a list of domain objects to viewmodels on the Controller in ASP.NET MVC

Hi, I'd like to know the best way of converting a list of domain object I retrieve into custom ViewModels in the controller e.g. IList<Balls> _balls = _ballsService.GetBalls(searchCriteria); into IList<BallViewModels> _balls = _ballsService.GetBalls(searchCriteria); it doesn't have to be exactly as I've outlined above i.e. it do...

Forms Issue Cross-Domain Posting to MVC Controller using JQuery

I have a very strange issue on my hands. I have two IIS websites using host headers. I have some simple code using JQuery and JQuery.forms to post a simple form to a controller. The controller returns JSON. It works great as long as the client code is present on the web site that has the controller code. The moment I move the form...

Compiler Error Message: CS0246 in ASP.NET MVC App

I have a new solution that is an ASP.NET MVC 2.0 application. I have added a porject to the solution which is a console application. The console namespace is foo, and it has a data repository called FooDataRepository which is a public class. I also have a public class in the foo namespace called FooLinkList, which is also public. In ...

Entity Framework and Object Context lifetime in ASP.NET MVC

Hi there I'm using Entity Framework in my project, and I have the problem that, once I pass my entities to a View (keep in mind that these entities have lazy-initialized objects along the lines of: Products.Owner, where owner is an object that is lazily initialized) I get a run-time exception telling me that the ObjectContext is out of ...

How can I redirect a user back to signout page when timed out? Asp.net MVC

Hi I have site that users lots of ajax(jquery). Now if the user times out for whatever reason(walked about for 30mins or something). On there next action I want them to be returned to the login page. I setup everything in the webconfig(returnUrl and timeout) and if they try to go to a page they have no premission to go to they get sent...

Spark View Engine "An assembly with the same simple name" error

I am trying out the Spark view engine with ASP MVC but get the error below when displaying a view. The view references model objects that are in a different assembly to the main web application (MyApp.Model.dll). I am stuck on the cause or resolution to this. Dynamic view compilation failed. 0,0): error CS1704: An assembly with the sam...

How do I create a new ASP.NET MVC website from template in Visual Web Developer 2008 Express?

I installed Visual Web Developer 2008 Express SP1 and then ASP.NET MVC 1.0, but when I go to File > New Website, ASP.NET MVC doesn't show up. ...

How to Create a Friendly URL in a CS File

I know how to create a url by using html.actionlink in the aspx file. But if I want to create the same url in a code behind file how would I do that? ...

Validate numeric text field in jquery

I have this code in jquery to prevent non-numeric characters being inputted to the text field $("#NumericField").numeric(); Now, on the text field i cant input non-numeric characters. That is OK. The problem here is if the user will paste on the text field with non numeric characters. Is there a way/method to disable pasting if the v...

Session Time Out never in asp.net mvc

I want my asp.net mvc(C#) application to be with the session without expire. The Session should be active forever the user opens the application. Whats the best way to do it? ...

ASP.NET MVC - Code Behind of Master Pages

Hi All, I am newbie for ASP.NET MVC 1.0. I am converting from a classic application built up with VS2008 .NET3.5. I created a master page, and the menu must be read from the database. Now the code that generate the HTML into the appropriate menu div in classic ASP.NET3.5 VS2008 was in the code behind of the master page. I cannot unders...

Setup a route {tenant}/{controller}/{action}/{id} with ASP.NET MVC?

I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would have a route with {tenant}/{controller}/{action}/{id}, each tenant representing an logical instance of the app (simply independent multi-user accounts) The fine grained details how do that are still quite unclear to me. Any guide available to setup such multi-...