asp.net-mvc

ASP.NET MVC: routing help

Consider two methods on the controller CustomerController.cs: //URL to be http://mysite/Customer/ public ActionResult Index() { return View("ListCustomers"); } //URL to be http://mysite/Customer/8 public ActionResult View(int id) { return View("ViewCustomer"); } How would you setup your routes to accommodate this requiremen...

Persisting complex data between postbacks in ASP.NET MVC

I'm developing an ASP.NET MVC 2 application that connects to some services to do data retrieval and update. The services require that I provide the original entity along with the updated entity when updating data. This is so it can do change tracking and optimistic concurrency. The services cannot be changed. My problem is that I need t...

controller path not found for static images? asp.net mvc routing issue?

I have an image folder stored at ~/Content/Images/ I am loading these images via <img src="/Content/Images/Image.png" /> Recently, the images aren't loading and I am getting the following errors in my error log. What's weird is that some images load fine, while others do not load. Anyone have any idea what is wrong with my routes...

What is the order of execution in ASP.NET MVC Controller?

Say I have a controller called "HomeController" which inherits from Mvc.Controller. Also say I have written the constructor of the controller and some filters for some actions. Public Class ClientController Inherits System.Web.Mvc.Controller Public Sub New() ''Some code End Sub <SomeActionFilter()> _ Functi...

asp.net mvc & jquery dialog: What approach do I take to add items to a dropdownlist/select list without full postaback?

Hi, I am new to MVC and have a grasp of the basic model, but still doing everything with postbacks etc. One aspect of the UI I want to build is to have a drop-down-list of items with a button to add an item to the database and refresh the list. Achieving this with WebForms was straight forward as everything was wrapped in UpdatePanels,...

jQuery UI Dialog Form and ASP.NET MVC

I'm not entirely sure if this is the best way to word it, however, I'm having a little trouble working out how to achieve. What I have is a page with a form on for editing a user's details. The page itself sits on /User/Edit/1234 where 1234 is the employee number. On that page there is a reset password link which opens the following jQ...

NerdDinner routing

I watched Scot hanselmann's presentation at mix '10. When he presented the tiny urls for Nerddinner he said it was a 2 part process. a) modify global.asax.cs with a new route b)some sort of isapi rewrite. When I implemented this in my asp.net mvc 2 site I only did part a. and it works. why then did he do part b?? what is the advantag...

ADO.net, Check if ObjectContext is writeable

I have an embedded database in an asp.net mvc project. If I try to write to the file, I sometimes get a write failed exception because the SQL Server can't write to the file. How can I check an ObjectContext, if its writeable, without actually writing something to the database? ...

ASP.NET MVC TempData used for wrong request

I use TempData to keep ModelState during redirects (using MvcContrib technique). This works fine. However, in rare cases, user aborts request and then immediate fires another (e.g. quickly clicks on another menu item). This causes ModelState errors to appear on that page, for which it does not belong. The problem is that TempData is sto...

ASP.NET MVC 2 - How do I use an Interface as the Type for a Strongly Typed View

I'd like to keep my concrete classes separate from my views. Without using strongly typed views, I'm fine. I just use a big parameter list in the controller method signatures and then use my service layer factory methods to create my concrete objects. This is actually just fine with me, but it got me thinking and after a little playing...

AJAX Post of JavaScript String Array to JsonResult as List<string> Always Returns Null?

I'm trying to build up a string array in JavaScript and get the results in a string list in the action method. Below is what my JavaScript looks like. I'm using jQuery 1.4.2. The problem is my List in the action method is always showing NULL. Will a JavaScript string array not map correct to a string list in C#? var test = ['tes...

Setting the value of a radio button with JQuery (ASP.NET MVC)

I have 2 "lists" of (4) radio buttons {value = "0", "1", "2", "3"} in all lists. The first list needs to drive the second list (which may occur multiple times). So if an option is selected in the first list, the SAME option is selected in the second list. It sounds weird, but it has a purpose. The first list is more of a "select all" ty...

Why does the default view for a List in ASP.NET MVC use 'var' to iterate through the items?

The title pretty much sums it up, it puts the following line of code in: <% foreach (var item in Model) { %> As the View is auto-generated and uses reflection to work out exactly what item is, so you get intellisense and everything, I just wonder, why do they use var rather than the actual type? ...

asp.net.MVC How to produce RESTful url like this: /mycontroller/myaction/24

Could someone show me the syntax of an Html.ActionLink that will produce a hyperlink that looks like this: <a h ref="/mycontroller/myaction/67">mylinktext</a> thanks. Terrence ...

jQuery autocomplete pass null paramter to the controller in ASP.NET MVC 2

I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return json in return. The problem is the parameter sent to the controller is always null. Here is the in-browser jQuery code for the autocomplete: $(document).ready(function() { var url = "/Building/GetMatchedCities"; $("#City").autocompl...

inject different implementations by logged User Role

public class TheController : Controller { IThe the; public TheController( IThe the) { //when User.IsInRole("r1") The1 should be injected else r2 this.the = the; } } public class The1 : IThe{} public class The2 : IThe{} //anybody knows a good way of doing this ? ...

Complete list of tools and technologies that make up a solid ASP.NET MVC 2 development environment for beginners

This question is related to another wiki I found on SO, but I'd like to develop a more comprehensive example of an automated ASP MVC 2 development environment that can be used to develop and deploy a wide range of small-scale websites by beginners. As far as characteristics of the dev environment go, I'd like to focus on beginner-friend...

How does the IIS 'courtesy redirect' affect ASP.NET MVC or other web frameworks?

I read in http://support.microsoft.com/kb/298408 that IIS6.0 automatically responds with a "courtesy redirect" (HTTP 301) on URLs that lack a dot. When a browser requests a URL such as http://www.servername.de/SubDir, the browser is redirected to http://www.servername.de/SubDir/. A trailing slash is included at the end of the URL. ...

How to set the width of the text box when using HTml.TextBoxFor

I have the following line in my view: <div class="editor-field"> <%= Html.TextBoxFor(m => m.Description)%> </div> How do I define the width of the text box? ...

Is there a suggested solution structure for ASP.NET MVC Production Apps

In general, I don't like to keep code (BaseClasses or DataAccess Code) in the App_Code directory of an ASP.NET Site. I'll usually pull this stuff out into a MySite.BusinessLogic & MySite.DataAccess DLL's respectively. I'm wondering should I be doing the same for ASP.NET MVC. Would it be better to Organise the solution something along t...