asp.net-mvc-2

Trivial JQuery $.ajax Json Post to ASP.NET MVC2 controller: Cannot get Controller to see JSON (or anything)

I went through dozens of answers to figure out the trick to posting data from $.ajax to a parameter in MVC 2's Controller. Here's as far as I got: BTW this works if you use a GET, but fails as a POST. How would I fix it? $(document).ready(function () { $.ajax({ type: "POST", url: "/Home/Get", data: {value:...

MVC2 - How to obtain parent model (container) inside template

I'm writing an MVC2 app using DataAnnotations. I have a following Model: public class FooModel { [ScaffoldColumn("false")] public long FooId { get; set; } [UIHint("BarTemplate")] public DateTime? Bar { get; set;} } I want to create a custom display template for Bar. I have created following template: <%@ Control Lan...

Render EditorTemplates based on authentication

Is it possible to render the editortemplates if a user is logged on and the displaytemplates as a default or do I need to create my own Html helper extension? ...

ASP.NET MVC2 and JSON model binding with validation to an action method

Phil Haack's blog entry describes this process using ASP.NET MVC 2's futures and Crockford's json2.js. John Resig also recommends using Crockford's json2.js in this article regarding "use strict";. To get this feature today, would you still download the MVC 2 Futures, or is this included in the MVC 2 final, or is this part of the new M...

Multiple types were found that match the controller named 'Home'.

I've just started using dotnetopenauth for my user registration. It's great, and is working perfectly. The problem is now I'm getting an error when I try to go to /Home/ which says: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}')...

Ajax.BeginForm Displays Partial as a New Page...

I have a partial view that I render on my Home/Index page. Its a short form with a viewmodel for and annotations for validation. It calls the controller and upon failure(since I don't type anything in and I have [Required] tags in my view model) it re-renders the partial view as a new page. My question is do I have to just return JSO...

Publishing to file system in visual studio 2010 is failing unexplainably

I am getting the following two errors when trying to publish my site to filesystem in visual studio 2010, Error 14 Copying file obj\Release\Package\PackageTmp\Areas\Admin\Scripts\homescroller.js to obj\Debug\Package\PackageTmp\obj\Release\Package\PackageTmp\Areas\Admin\Scripts\homescroller.js failed. Could not find file 'obj\Release\...

ASP.NET MVC2 and EF4 - Creating checked checkboxes in an Edit view

I'm currently in the process of creating a shared Edit/Create view for my game review project and have hit a snag. Each game can be a title on a variety of platforms. I have this mapped as a many-to-many relationship in my EF4 model. For my view, I'd like to have a series of checkboxes with the names of each platform, and, for the Edi...

ASP.NET MVC 2 - Binding To Abstract Model

Hi Guys, If i have the following strongly-typed view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<XXX.DomainModel.Core.Locations.Location>" %> Where Location is an abstract class. And i have the following Controller, which accepts a strongly-typed Model via a POST: [...

ASP.NET MVC Redirect with model

Hi, I currently have a method in my controller which accepts a form collection, saves the data, and then displays the data in a 'Details' page. At the moment, the code currently looks something like: [HttpPost] public ActionResult Create(PersonModel person)<br> { if (person.IsValid()) { person.additionalData = "Person c...

How to create a Cookie using SSL pages?

Hi, I have an ASP:NET MVC 2 web site that is on SSL. I want to create a cookie like this: FormsAuthentication.SetAuthCookie(validatedUser.UserName, false); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, validatedUser.SecureToken, DateTime.Now, DateTime.Now.AddMinutes(10), false, String.Empty); HttpCookie coo...

"A potentially dangerous Request.Form..." error in MVC 2.0

ValidateInputAttribute, ValidateInput, httpRuntime requestValidationMode="2.0" in web.config (system.web) all do not fix, also the "ValidateRequest="false"" in my view. I'm using MVC 2, Visual Studio 2010, .NET 4.0, and I'm still getting the following error: A potentially dangerous Request.Form value was detected from the client (Body=...

Automating unit tests for asp.net mvc

Today I finally started to write some unit tests for my new ASP.net MVC project seriously. Some unit tests, however, kept returning for every action in a each controller: Perform a test whether the returned ActionResult is not null. Perform a test whether the action returns a valid ActionResult if the ModelState is invalid. Perform a t...

How do I display a datatable in asp.net mvc 2 ?

I am running a dynamically built SQL statement and putting the results in a datatable. I then need to display these results as a table in a partial view. I would normally create a List<> object and strongly type it to the page, but in this case I do not know what the final sql will be, since it is built by the user at run time. So, how ...

ASP.net MVC deployment to IIS7

I'm trying to deploy a MVC application to a news Server, I have .net framework 4 and ASP.net MVC2 installed. My app pool is assigned to .net 4, integrated mode. But for some reason, the routing is not happening properly. I am getting a 404 error on links and not properly routed to the controller. What am i missing here? Is it might be or...

ASP.NET MVC2: Database Result Scoring Methodology

One of the projects I am working on is a search engine. This search engine has 36 parameters that can be set to a search within the form, and results are displayed through a series of scoring mechanisms. For example, if you were searching for a desk with a certain width, it would find the desks closest to the desired width and then sor...

Manually adding text to html.ValidationSummary?

I am rather new to mvc2 and when following a writeup on data annotations and such, I came across a bit of code that let me manually add a line of text to the validation summary. I've searched for the last 2 or 3 hours and I've come to the point where I think I'm just searching for the wrong thing. Its not custom validators I'm looking f...

How to scroll a table horizontally?

I have a table built from a dataset that is displayed in a partial view. The table is larger than the bowser. How can I get the table to scroll horizontally in my partial view? ...

Your thoughts on "ASP.NET MVC 2 in Action"

Hey fellow ASP.NET MVC devs, I'm looking to buy ASP.NET MVC 2 in Action but I wanted to see if anyones read it and if they would recommend it/or another ASP.NET MVC book. I've already read NerdDinner and I really enjoyed it but am hoping to extend my knowledge and read something else. The description seems quite promising but as they s...

MVC Form in MasterPage not working.

Ok, This is a bit confusing and frustrating. Here's what I have in my masterpage : <%using (Html.BeginForm("Index", "SearchController", FormMethod.Post, new { @name = "dosearch" })) {%> <input type="text" name="ssearch" class="search"><a href="#" oncli...