asp.net-mvc-2

Relating multiple tables to each other in SQL

Hi! This is more or less a best-practice question: I'm working on a site that requires me to relate some tables to several different tables. For instance, I have a Comments-table, that I would like to relate in a way such as one might comment on entities in Table A, but also in Table B separately. Similarly, I have a rating-table that...

How do I edit WCF Data Service objects with ASP.NET MVC 2?

I don't want to put any more code into my controller than I have to. This works: // // POST: /Duty/Edit/5 [HttpPost] public ActionResult Edit(Duty Model) { Duty Attached = (from Duty d in ctx.Duties where d.Id == Model.Id select d).Single(); Attached...

Why does moving classes into a new folder in Visual Studio break things?

I have an ASP.NET application with three areas. In the root of the application is a Models folder containing a hodgepodge of classes, including two DataContexts, some Repository classes, some ViewModel classes, some helper classes, and some business logic classes. I'd like to create subfolders for each of these subcategories and move t...

ASP.NET MVC 2 and SQL Table Profile Provider

I'm trying to add the sample table profile provider from http://www.asp.net/downloads/sandbox/table-profile-provider-samples to a new MVC 2 site. After a bit of research and fiddling around, I've arrived at a profile class that looks like this. namespace MyNamespace.Models { public class UserProfile : ProfileBase { [Set...

What is the best practice for accessing Session variables in Asp.net MVC?

I am developing a website in Asp.net MVC. I pass the HttpContext to the Model from the Controller in the Model's constructor to get access to the Session so I can manipulate the Session variables. I am assuming that this is just a reference and won't incurr a huge performance penalty. I am keeping my controllers clean by doing this but I...

Using ASP.NET MVC 2 to display joined record

I'm building out a simple simple ASP.NET MVC 2 page. Was able to do the Edit page the way I want, but am having some trouble with the Index page. I have a table tblContacts that is joined by another table tblStates, database is normalized so the contact table (name, phone, address, city, etc) has a StateId which references a tblStates ...

asp.net mvc datannotation unique field

i followed http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx . it was fine till server side but how would i be applying client side validation for unique field validation scenario on for example say username. i want to have username as unique. ...

How to adapt a simple String Extension to support SQL

I've got a C# string extension that really makes life easy, but I am getting the exception: Method 'System.String ToUrlString(System.String)' has no supported translation to SQL. I've seen this as a common problem and some people have found ways around fixing this for their method, but I'm not sure it's possible for mine. It's just a ...

HttpPost Action for updating my model with children from the edit page

I have a simple MVC 2 blog that I'm building as I learn. My edit page has title, body, date, enabled and tags. The tags is where my problem comes in. I have a Tags table and a Posts table and tags are associated to a post through the PostTag table. I have my linq model setup properly and I even have the Add HttpPost action working. My ...

Mvc2 dropdown list returning val as string, want to change the type.

So I have some drop down lists in a view (apologies for the wall of code, thought it better to post to much than not enough): //...blah... <%=Html.DisplayFor(m=>m.PlanType.PlanTypeType) %> <%=Html.DisplayFor(m=>m.YearLevel.YearLevelName) %> <%=Html.DisplayFor(m=>m.Subject.Subject1) %> //..moreblah... rendered via an editor...

Preventing Session Timeouts in asp.net mvc

i have a form where user enter some information. The problem is when they submit the form, due to session timeout, the page redirected to login page. After login they return to the same page but the form is empty and all information is lost which is very annoying for the user. What is the best solution? I don't want to refresh the page....

JQuery UI Selectable stop event doesn't work in IE

I have a JQuery select component and a javascript function to handle the stop event: <script type="text/javascript"> $("#selectable").selectable({ stop: function() { $(".ui-selected", this).each(function(i, selected) { if ($(selected).text() == "Google") { ...

Migration to Asp.Net MVC 2: App_Themes?

I am migrating an Asp.Net 2.0 WebSite to an Asp.Net MVC 2.0 Application. In the Asp.Net WebSite Themes and skin features are used for customizing UI. I would like to handle this in Asp.Net MVC 2.0. Is there a good way to migrate the Themes and Skins in Asp.Net MVC 2.0. EDIT: I have looked into some of the solutions on the net and othe...

How to preselect item in Html.DropDownlListFor()

Hi all How can i preselect item in Html.DromDownListFor() ? i have code in view which inserts items to DropDownListFor <div class="editor-field"> <%var mesta = new List<SelectListItem>(); SelectListItem aa = new SelectListItem(); aa.Text = "---------VYBER MESTO---------"; aa.Valu...

ASP.net MVC 2.0 Asynchronous Controllers - What happened to the Delegate Pattern?

I'm migrating a project to the MVC 2.0 RTM version, and have hit a snag. I have a couple of asynchronous controllers based upon the older MVCfutures (1.0.0.0) This previous release let me do very clean asynchronous methods (see below for example) EDIT: Work around was to retain the previous futures version. Need a solution moving forw...

MVC omit optional page parameter

I have the following URL in mind: /restaurants/italian/miami.html /restaurants/italian/miami-p2.html Using these routes routes.MapRoute(null, "{category}/{branch}/{city}-p{page}.html", new { controller = "Branch", action = "Index" }); routes.MapRoute(null, "{category}/{branch}/{city}.html", new { contr...

Creating Database Mocks in ASP.NET MVC using Data from Existing Database

I have an existing ASP.NET MVC application with some sample data in the SQL Server database, which is working fine.. Assuming I have all of the necessary repositories and IOC in place, is there a tool that will extract the data from a group of tables, and "freeze-dry" it into a mock object (perhaps using an XML file to store the data)...

Why does the HTML in my JSON response get encoded?

I'm using this blog post as a guide, detailing how to use jQuery with jTemplates to stuff a JSON response into a template. My problem is, one of the returned fields (named Description) contains HTML, but the HTML brackets are getting encoded to \u003C and \u003e. Here's the HTML (in the Description field) the server returns: <a href="...

Custom route & area in MVC 2

i'd like to map areas like this: /artists/{artistName}/images /artists/{artistName}/images/{imageId} /artists/{artistName}/blogs /artists/{artistName}/blogs/{blogId} /artists/{artistName}/albums /artists/{artistName}/albums/{albumId} in mvc2, how do i configure my area route and what does my file structure for my area view look like? ...

Asp.net MVC 2 modelbinder fails to generate List on Post

I have created an EditorTemplate to be in charge of rendering a collection of phone number edits for a couple of my views in my latest project. My EditorTemplate excpects a List of PhoneNumberModel. It seems as though all of my element names that are tied to the PhoneNumberModel are being give an extra period PhoneNumbers.[index].[Prop...