asp.net-mvc

How do I get a DropDown to have a selected value when I display the form in asp.net mvc?

Here is what I have in the controller: IList<LocationInFacility> locs = LocationsInFacility(custCodeID); ViewData["LocationsInFacility"] = new SelectList(locs, "ID", "Name", "DL"); Here is the view: <label>Location in Facility</label> <%= Html.DropDownList ("LocationsInFacility",(SelectList)ViewData["LocationsInFacility"]...

Where should I put my asp.net-mvc strongly typed viewdata?

I've been nesting my viewdata classes inside my controllers and, as their numbers grow, I'm starting to ask myself if this is a good idea. Then again, something about polluting the /Views and /Controllers directories with these things seems off. Is there a convention I'm missing here? Maybe a /ViewData directory? idk, what are some good...

ASP.NET MVC returns wrong path for Url.Content

I have an ASP.NET MVC app which runs fine under the debugger running from http://localhost:9002/ But when I publish it to http://localhost/Zot/ the calls to Url.Content are returning incorrect values. I have script tags like <script src="<%= Url.Content("~/Scripts/util.js") %>" ... In the published site this produces: <script src="...

Can you use ASP.NET MVC Futures library and MVC source code side by side?

I'm trying to using the Html.RenderAction<> method from the ASP.NET MVC Futures library. However, I can only make this work if my project references the System.Web.Mvc assembly in the GAC. If I include the System.Web.Mvc source code as a project in my solution, then everything with Microsoft.Web.Mvc blows up. Anyone else have this exp...

Error when I try to use the MVC Futures library with the ASP.NET MVC source code in the same solution.

I get the following error when attempting to use both the MVC Futures library (Microsoft.Web.Mvc) and the ASP.NET MVC source code in the same solution: The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyTo...

How do you handle a variable number of MVC routes?

I note this intriguing bit in ASP.NET MVC: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); I'd like to map {*pathInfo} into a route. Something like: routes.MapRoute( "area/{*pathInfo}", "{controller}/{action}/{id}",parameters new { controller = "Area", action = "Index", id = ??? } ); but how do I pass in the variable "f...

How ASP.Net MVC ActionLink Works ?

I am trying to write my own LightWeight MVC for .Net 2.0 using NHaml as view Engine. In ASP.Net 3.5 MVC, In View file we used to specify link by code snippet. Html.ActionLink("Add Product","Add"); In MVC Binary, there is no function to match this call. I Only found, (In class System.Web.Mvc.Html.LinkExtensions ) public static strin...

What is the MVC Futures Library ?

On Stack Overflow, I've seen a few people referring to the MVC Futures library What is this project? How do I use it? Where is the documentation? ...

Password fields not clearing on submit in asp.net mvc

I have a user preference page in which the user can type in their current password, new password and confirm new password. When the user submits the form it sends them to an action. The problem is that when the form submits, the password fields stay filled. I want them to clear. I attempted javascript but when I use document.preferen...

Single Controller with Multiple Views

I am trying to create an MVC application with multiple view, but using a single controller. I started by creating a second route with another property that I could use to redirect to a second folder. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); ...

Default model binder and complex types that include a list

Hi All I'm using RC1 of ASP.NET MVC. I'm trying to extend Phil Haack's model binding example. I'm trying to use the default model binder to bind the following object: public class ListOfProducts { public int Id { get; set; } public string Title{ get; set; } List<Product> Items { get; set; } } public class Product { pu...

Modifying Data Binding in ASP.NET MVC RC2

How can I modify the behavior of the autobinding in ASP.net MVC? For instance, suppose I have a simple Employee object. One of the fields might be hiredate. When this field is bound to a textbox, it displays mm/dd/yyyy hh:mm:ss instead of just the date. I know I can modify the view to add formatting, but I'm pretty sure I the autobin...

ASP.net MVC RC 2 - Won't Install... Because NGEN is having Catastrophic failures!

I see that the new ASP.NET MVC 1.0 Release Candidate 2 is out. No posts yet on Scott Gu's blog. Any idea's if this has broken anything? I'm currently using the beta version of the MVC with a couple of projects. I am about to start a new one. Does the RC 2 break anything when moving from the Beta version? [Update] Not able to insta...

ASP.Net MVC RC2 Ajax.Form becoming Ajax.BeginForm stopped working

Hi all, We just upgraded from TCP 4 to RC 2 of the MVC framework for .net. The following code, which worked, now just does a regular post (ie. navigates to the create page): <% using (Ajax.BeginForm("Create", "LEEDBoardItem", new AjaxOptions() { UpdateTargetId = "LEEDBoardDisplay", HttpMethod = "POST" })) { %> <%= Html...

How do I add relational data to an ASP.net MVC data entity Create view?

Let's say I have a table of staff members, and a separate table of staff roles in a many-to-many relationship (ie, with a StaffMembersInRoles table in between). Using the ADO.net entity framework we have an object model like this: I have a StaffController controller with a create method and a Create view which is pretty much the standa...

How do you pass class as a key value pair of ASP.NET MVC htmlAttributes?

I would like to pass the html input class attribute in ASP.NET MVC for my input box using Html.TextBox("FullName", null, new{class="grey-input"}). But I think I can use the "class" keyword. How can I bypass this issue? ...

How to handle general exceptions in Asp.Net MVC?

I want to transfer all unhandled exceptions to an error page in Asp.Net MVC. What is the way to handle the unhandled exceptions in Asp.net MVC? Is there anything like application_error? ...

MVC + Templates

Hi all I am working on a system that gets templatse dynamicly, they contain tags like {{SomeUserControl}} {{SomeContent}} I was wonder how I could use MVC to render those templates and replacing the tags in the best possible way as the templates will be edited via a web front end, and the content / macros will be create from the same ...

Passing an Anonymous Type to UpdateModel/TryUpdateModel in ASPNETMVC

Given the following controller method: [AcceptVerbs("POST","GET")] public ActionResult apiMapInfo() { var x = new { Lat = "", Long = "", Name = ""}; var mapInfo = new DALServices.Models.MapInfo(); // Updates correctly TryUpdateModel(mapInfo); // Does not update correctly TryUpdateModel(x...

Using ASP.NET default Model Binders with DateTime

Hi, I've been trying to use the default ASP.NET MVC model binders but I'm having issues with binding DateTime. I've looked at Scott's post here but it seems to be too sophisticated. Is there a simpler solution to binding DateTime? ...