asp.net-mvc

Global error handling (outside of controller) in ASP.NET MVC

Let's say I put the following code somewhere in a Master page in my ASP.NET MVC site: throw new ApplicationException("TEST"); Even with a [HandleError] attribute placed on my controller, this exception still bubbles up. How can I deal with errors like this? I would like to be able to route to an Error page and still be able to log t...

Why isn't DataContractJsonSerializer serializing my Id property?

I'm using LINQ-to-SQL for CRUD functionality, and DataContractJsonSerializer to serialize the object to JSON. I am also using ASP.NET MVC's data binding to post values to an MVC action that does the inserting. The problem is that it will serialize all of the properties except the Id property. I've got the model set up as so: [Serializab...

Programatically get list of MVC Views?

Is there a way to get a list of all the Views defined in an ASP.NET MVC project? Is there a built-in enumeration anywhere or should I be looking toward reflection? ...

ASP.NET MVC: How do I send "text/xml" to all browsers but IE?

I need to be able to send the content type "text/xml" to Firefox and Safari, to allow them to render inline SVG in one of my pages. This works, as long as the content type is "text/xml". However, when IE hits the page, if the content type is not "text/html" it tries to render the XML document tree, rather than the XHTML content of the ...

Using Microsoft Data Entity Framework with Microsoft MVC on Mono 2.4

I'm using Mono 2.4 on the Ubiquity web hosting service. I created a simple MVC tutioal applciation, linked here, and verified that it worked using all Microsoft tools. Next, the application was updated to point to a MySQL server database running on my Ubiquity host. The application works great on a Microsoft based machine. Now, I am...

change AM to PM?

Hi I am sending in a strings in with the date part, hour part and minute part and AM/PM Now I want to make this into a DateTime. But I am unsure how to change the time part to AM/PM depending on user choice. How do I do this? ...

Make all form fields readonly in MVC

I am displaying 3 or more versions of a form. One version is an edit form to edit all fields. A second version will be a read only version of the same form which will be used to show all the same fields but with all fields having readonly="true" on the client side so that the user cannot enter data. The readonly fields need to use a di...

Asp.net Mvc: Filters nullable parameter

Hello, I am trying to use a nullable datetime and double as a parameter for an actionfilter but it's gives the following error: 'Propertyname' is not a valid named attribute argument because it is not a valid attribute parameter type I thought a quick google would solve it but to my surpise I couldn't find a lot of info about it....

mvc2 Html.label("mystring") mangling

Given the MVC2 code below why is the second label getting mangled? <%=Html.Label("DisplayFor(" + "DateHired,\"Date\"):") %> <%=Html.Label("DisplayFor(" + "c=>c." + "DateHired,\"Date\"):") %> <%=Html.DisplayFor(c=>c.DateHired,"Date") %> results in: DisplayFor(DateHired,"Date"): DateHired,"Date"): 2/28/1999 ...

Help me come up with a deployment strategy

So I have an ASP.NET MVC website I am developing and never had a decent deployment strategy so making changes, especialy database scheme ones can involve a lot of steps and time. Here are the steps I am looking todo and would like suggestions on how to do it or tools (preferably free). Feel free to point out any missing steps or things ...

How can I get the "Add -> View" menu item when adding ASP.NET MVC pages to a Web Forms project?

I'm adding some ASP.NET MVC pages to an existing ASP.NET Web Forms project. I've been able to port over some models, views, and controllers from an MVC project I created and they're working great. But I'd like to add some new "Strongly Typed" views to my project, but I don't get the New View Wizard in my Web Forms project. I'm a bi...

What are some Performance [Dos/Don'ts] in C# -ASP.NET

I am finalizing one of my projects and taking a look over the whole project looking for mistakes, bugs and performance mistakes. I am using MVC. I caught one Don't and that is: Never put a RenderPartial within a loop. it will drastically slow down your whole server. ...

ASP.NET MVC - I am having trouble storing and displaying an image in a database

Hello, I have been pulling my hair out about this since Friday and I am going nuts. I want to have the ability for a user to submit a form with an image, and have that image stored into a database. Then I want that image displayed on my index view. I have tried all of the other stackoverflow help topics on here already and none of th...

ASP.NET MVC Validation of ViewState MAC failed

After publishing a new build of my ASP.NET MVC web application, I often see this exception thrown when browsing to the site: System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not supplied or was invalid. ---> System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Far...

Vanity MVC Routes?

I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the company names need to map to the same "base" controllers, regardles of what the name is. I only need the companyName for authentication purposes. Also, if there's no companyName provided, I need to map to a different set of co...

How can I programatically access the ASP.NET route table from a filter?

Is the route table available from the filters? I'm inheriting from the AuthorizeAtrribute class. All I'd like to do is examine the route table, and then just call the base class (after making some minor setup adjustments). I could look at the raw url, but I'd rather get the value I need from the route table. Any ideas? ...

How to pass thw Viewdata to all the views in my controller ???

i have a dropdown list which select a value [AcceptVerbs(HttpVerbs.Post)] public ActionResult Screenname(FormCollection collection) { Viewdata["screenname"] = collection[0]; return RedirectToAction("Index", new { ScreenName = ViewData["screenname"] }); } then i want to access this ViewData in other ac...

ASP.NET MVC ViewModel Pattern

EDIT: I made something much better to fill and read data from a view using ViewModels, called it ValueInjecter. http://valueinjecter.codeplex.com/ using the ViewModel to store the mapping logic was not such a good idea because there was repetition and SRP violation, but now with the ValueInjecter I have clean ViewModels and dry mapping ...

Resharper (R#) 4.5 and MVC (1.0) solutions cause Visual Studio 2008 SP1 to crash on solution load

Does anyone have the issue with Resharper where opening a solution with MVC projects causes Visual studio to close/crash? No Errors, no warning, just close. To fix the problem, I have to delete the bin and obj folders from the MVC project directory which allows the solution to be opened again. When the solution is loaded, sometimes ope...

ASP.NET MVC: Validation messages set in TryUpdateModel not showning ValidationSummary

I've been trying to follow the validation tutorials and examples on the web, such as from David Hayden's Blog and the official ASP.Net MVC Tutorials, but I can't get the below code to display the actual validation errors. If I have a view that looks something like this: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Sit...