asp.net-mvc

DataContractJsonSerializer ReadObject Exception

I am following the accepted answer of ASP.NET MVC How to pass JSON object from View to Controller as Parameter. Like the original question, I have a simple POCO. Everthing works fine for me up until the DataContractJsonSerializer.ReadObject method. I am getting the following exception: Expecting element 'root' from namespace '...

can't access to an extension method with UrlHelper parameter in controller! Vice versa in view have access

why defined extension method with UrlHelper don't added in Url.EXTENSIONMETHOD when i want to use it in controller! but i have access to it in view? public static string Home(this UrlHelper helper) { return helper.RouteUrl("ABC", new { controller = "ABC", Action = "Default" }); } i haven't access: public ActionResult Default() { ...

Best practices for "search data class" in ASP.NET MVC

Hi everybody, I'm hoping this isn't too subjective, but I'm new to ASP.NET MVC and I'm trying to figure out how others may have solved similar problems. Basically, I have two entities, Customers and Orders. A customer has many orders; an order belongs to exactly one customer. I'm making an Order Search feature that should allow a user...

ASP.Net MVC2 (RTM) breaks response filtering - "Filtering is not allowed"

I've just done a test run of upgrading a project to ASP.Net MVC 2 (RTM) in anticipation of the full official .Net 4.0 release coming later this month. Our application is using a minimizer for our CSS and javascript. To do so, it is making use of the HttpResponse.Filter property to set a custom filter. With the upgrade, the setter for ...

Storing data in HttpContext.Current.Items vs ViewData

When is it appropriate to store data in HttpContext.Current.Items[...] vs storing data in ViewData[...]? I'm trying to figure out the best practices for storing data in this collection and I'm not sure if it's safe to store user-specific data in HttpContext.Current.Items. One use-case is passing down user credits from a base controller...

How to use authentication cookie from WCF Authentication Service in an ASP.Net MVC application

Okay, I've had little luck finding any documentation or tutorials for my specific scenario. I have an ASP.Net MVC web application that will be using WCF services for everything including authentication and roles (via membership providers on the WCF backend). I've had no problem setting up the authentication services but it does not se...

Performance of String literals vs constants for Session[...] dictionary keys

Session[Constant] vs Session["String Literal"] Performance I'm retrieving user-specific data like ViewData["CartItems"] = Session["CartItems"]; with a string literal for keys on every request. Should I be using constants for this? If yes, how should I go about implementing frequently used string literals and will it significantly affec...

What is the best way to implement a callback scenario using WCF and ASP.NET MVC?

I am new to WCF. I just finished reading Learning WCF and I think I've got a pretty good grasp of the fundamentals. I am adding functionality to a line of business app that runs on ASP.NET MVC entirely inside the corporate LAN. I am calling into a service that will also send me events as they occur (and not as responses to service calls)...

ASP.NET MVC vs Winforms MVC

Why does MVC work so well in ASP.NET but not in (.NET) winforms? There isn't an explicit MVC for winforms offered from Microsoft. However, I see people attempting to use one but they are a bit of a mess compared to ASP.NET MVC. ...

Generating jquery 'rules' from business model to UI in asp.net mvc

Hi all, I've had a good look around and am certain that there's no matching question on SO, so here goes. Has anyone created a 'helper' method on their model that generates jquery (or plain javascript) rules validation dynamically, based on the criteria/rules that are contained within the object and taken from a repository (i.e. DB). ...

ASP.NET MVC 2 RC2 Model Binding with NVARCHAR NOT NULL column

PLEASE NOTE: I've answered my own question with a link to an answer to a similar question. I'll accept that answer once I'm allowed to (unless anyone comes up with a better answer meantime). I have a database column defined as NVARCHAR(1000) NOT NULL DEFAULT(N'') - in other words, a non-nullable text column with a default value of blank...

ASP.NET MVC project won't start under IIS 5.1 on Windows XP SP3

I've a ASP.NET MVC 2 project that runs fine under Windows 7 and will start on Windows XP if I use the Visual Studio Development Server, however, starting under IIS generates an error: Unable to start debugging on the web server With the message The specified procedure could not be found No errors in the system event viewer. If I ...

How to code a C# Extension method to turn a Domain Model object into an Interface object?

When you have a domain object that needs to display as an interface control, like a drop down list, ifwdev suggested creating an extension method to add a .ToSelectList(). The originating object is a List of objects that have properties identical to the .Text and .Value properties of the drop down list. Basically, it's a List of Select...

ASP.NET MVC: Can I use the MicrosoftMvcValidation.js functions to make an <input type=file> mandatory?

I have a form with a file-upload button plus some other entry fields and a submit button. I want the submit button to be enabled only if a file has been selected. I could probably do this with JQuery, but I figured that since I'm already including the MicrosoftMvcValidation.js scripts there might be something in there that I could use? A...

RadioButtonFor in ASP.NET MVC 2

Can someone provide a simple example of how to properly use Html.RadioButtonFor? Let's say it's a simple scenario where my model has a string property named Gender. I want to display two radio buttons: "Male" and "Female". What is the most clean way to implement this while retaining the selected value in an Edit view? ...

What is this message?

**c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(0,0): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is req...

Custom IIdentity and passing data from an attribute to a controller

Here's my scenario: I've successfully created a custom IIdentity that I pass to a GenericPrincipal. When I access that IIdentity in my controller I have to cast the IIdentity in order to use the custom properties. example: public ActionResult Test() { MyCustomIdentity identity = (MyCustomIdentity)User.Identity; int userID = ide...

Questions on about TDD or unit testing in ASP.NET MVC

I've been searching on how to do Unit testing and find that it is quite easy, but, what I want to know is, In a asp.net mvc application, what should be REALLY important to test and which methods you guys use? I just can't find a clear answer on about WHAT TO REALLY TEST when programming unit tests. I just don't want to make unnecessary ...

How to implement parent-child windows and pass values from child to parent?

I am working on an ASP.NET MVC 2 application. In one of my data entry forms, I have an "employer" field which has a "search" link next to it. When a user clicks on this link, another window is opened with a search form. The user uses the search form to search for the correct employer. A list of employers is shown to the user. Currently,...

Passing URL parameter and a form data together

I have following URL: http://localhost:49970/Messages/Index/9999 And at view "Index" I have a form and I post the form data to the action Index (decored with [HttpPost]) using Jquery, like this: View: <script type="text/javascript"> function getMessages() { var URL = "Index"; $.post( URL, $...