asp.net-mvc

ASP.MVC 1.0 serialization error not trapped by IExceptionFilter

Hi, I'm using ASP.NET MVC 1.0 and have exeption handling manged by a global controller activated by the HandleException attribute on the main controller. I've noticed that if I have an action invoked by an AJAX call, and that action fails with an internal ASP.NET error (e.g. I've tried to serialize an anonymous object) then the ASP.MVC...

Return Multiple Objects Using ASP.NET MVC'S JsonResult Class....

Is it possible to Multiple Objects Using ASP.NET MVC'S JsonResult Class.... Here is a controller method which returns json object of my records but i also want to pass the count value.... var materials = consRepository.FindAllMaterials().AsQueryable(); var count = materials.Count(); var results = new PagedList<MaterialsObj>(materials, c...

Response.Redirect not working inside an custom ActionFilter

My code is the following public class SessionCheckAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (/*condition*/) { filterContext.HttpContext.Response.Redirect("http://www.someurl.com",true); } base.OnActionExecuti...

How can I map stored procedure result into a custom class with linq-to-sql?

I have a stored procedure that returns a result set (4 columns x n Rows). The data is based on multiple tables within my database and provides a summary for each department within a corporate. Here is sample: usp_GetDepartmentSummary DeptName EmployeeCount Male Female HR 12 5 7 etc... ...

ASP.NET MVC <OutputCache> SqlDependency (CommandNotification?) with LINQ queries

Hello, I use LINQ queries in my ASP.NET MVC application and want to use OutputCache in some of my Actions. I hear this should be possible with CommandNotifications. But those seem to only go for self-created SQLCommands, or am I wrong? Can I manually tell SQL server to send SQLDependency notifications if certain tables change? And if...

Trying to update an ASP.Net MVC 1.0 project to MVC 2.0

I'm trying to update my project to ASP.Net MVC 2.0 from MVC 1.0. I've removed the references for System.Web.MVC to the newer versions. I'm getting an exception from the HTTPContext which reads "CurrentNotification = 'HttpContext.Current.CurrentNotification' threw an exception of type 'System.PlatformNotSupportedException'". What other...

ASP.NET MVC 2.0 Unused Model Property being called when posting a product to the server?

i have my auto-generated linq to sql classes, and i extend this class using partial classing (instead of using inheritance), and i have properties that that i've put in later which are not part of the database model and should not be. these are things like "FinalPrice" and "DisplayFinalPrice" - in the dbase, there is only RetailPrice and...

ASP.NET MVC: shortcut for Response.Write and String.Format

I've found a pattern in my Views like this: <% if (someCondition) { Response.Write(string.Format("Foo {0}, Bar {1} Baz {2}.", userName, someCounter, someDate)); } else { Response.Write(string.Format("Foo is {0}.", bar)); } %> The basic pattern of if...else with a bunch of repeated Response.Write(string.Forma...

ASP.NET MVC 2.0: Using Partial Classing or Inheritance on Database/Object Model?

I ask this because i'm using Partial classing to extend my db model, and in doing so some snags i've run into using inheritance and also snags i've run into declaring my db model in another class as a property and just using it like that ie: Public Property DBModelClass as DBModelClassType - however, doign direct partial classing has wo...

Asp.net: Replace GenericPrincipal

Hello, I was wondering what the best way is to replace the genericPrincipal with my own CustomGenericPrincipal. At the moment I have something like this but I aint sure if it's correct. protected void Application_AuthenticateRequest(Object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCook...

Button Onclick event (which is in codbehind) doesn't get triggered in MVC 2

I had an MVC 1.0 web application that was in VS 2008; I just upgraded the project to VS 2010 which automatically upgraded MVC to 2.0. I have a bunch of viewpages have codebehind files that were manually added. The project worked fine before the upgrade, but now the onclick even't don't get triggered. I.e. I have an asp:button with an ...

How can I set a default content-type of text/html in my web.config?

I'd like to set the default content-type for web pages in my ASP.NET MVC application to text/html. I know this can be done by adding a ContentType="text/html" to all of my <%Page%> elements, but I'd prefer to use the web.config instead. How can I do that? Thanks, Adrian Edit: I know that "text/HTML" is the ASP.NET default, but for u...

What's the Microsoft Ajax equivalent to jquery.ajaxSetup() or .ajaxError()?

I have an ASP.NET MVC site that uses both Microsoft Ajax [Ajax.BeginForm()] and jQuery to make asynchronous requests. I want to configure both frameworks such that a generic error handler is automatically attached if the developer does not explicitly specify a failure callback. In jQuery I can accomplish this with either .ajaxSetup() or...

How to Return A File and a strongly Typed data at the same time?

Hi I am using asp.net mvc 1.0 and I want to return a XML file but I also want to return a strongly typed data back so I can update some fields. Like the XML file will contain users who failed to be inserted into the database. So I want that to appear as a dialog save box what asp.net mvc return file() would do. However I also want to ...

How do you install Castle Windsor IOC?

I'm currently reading Pro ASP.NET MVC Framework by Sanderson. In the book he recommends setting up IoC using Castle Windsor, and he points out that the download automatically installs it and registers the Castle DLLs in the GAC. Well, at this point in time (5/4/2010), the Castle Project no longer has a downloadable installer that sets ...

ASPNET MVC - Override Html.TextBoxFor(model.property) with a new helper with same signature?

I want to override Html.TextBoxFor() with my own helper that has the exact same signature (but a different namespace of course) - is this possible, and if so, how? The reason for this is that I have 100+ views in an already existing app, and I want to change the behaviour of TextBoxFor so that it outputs a maxLength=n attribute if the p...

How to mock the Request.ServerVariables using MOQ for ASP.NET MVC?

hi guys, i'm just learning to put in unit testing for my asp.net mvc when i came to learn about the mock and the different frameworks there is out there now. after checking SO, i found that MOQ seems to be the easiest to pick up. as of now i'm stuck trying to mock the Request.ServerVariables, as after reading this post, i've learned th...

How to find in which controller/action an error occurred?

I'm logging all errors occuring in my OnException method. How to find in which controller/action an error occurred? ...

Is this valid data for jquery ajax call to aspnet mvc controller?

I am using jquery with asp.net mvc.... Is my data option valid or am i missing some thing... $.ajax({ type:"POST", url: "Materials/GetRecords", data: "{'currentPage':1,'pageSize':5}", Any suggestion.... EDIT: I am calling a function from a view page, <asp:Content ID="Content2" ContentPlaceHolderI...

view and action method name

where does mvc stores the association between action method name and view page name? or who is responsible for checking if the there is a view page with name same as action method name? ...