asp.net-mvc

ASP.NET MVC custom T4 templates for views

When I'm adding a new strongly-typed view to an ASP.NET MVC project, I can select between different view content templates (Create Details, Edit, List). I have read these are templates based on the Visual Studio T4 code generation engine. How can I author and configure my own templates and let them appear in the available templates when...

TempData[] getting wiped

I have a integer stored in TempData, and it is getting periodically wiped for an unknown reason after 30-60 seconds of browsing around my site. I have a break point on the place where the value is set and its never being set to null, yet somehow that value in TempData is getting nulled. Any idea why this is happening? ...

When is it acceptable to use the ViewData dictionary in ASP.NET MVC?

It seems like most people are leaning towards creating single ModelViews for each view (Thunderdome Principle) in lieu of stuffing in weakly typed items into the ViewData dictionary. So, with this in mind, for what tasks should the ViewDictionary be used for then? Really small one-off views? Don't use it at all? ...

How to specify actions without using Helpers

I am going to be generating some hyperlinks on the fly driven from our database. So for example I go and get some information about a project, then based on the configuration information in that DB table (Which contains information like type of HTML fields to generate) I'll dynamically create Html controls from a custom control I create...

Signals in Linq to Sql?

Does anyone know of a way to do something similar to Django's signals using LINQ to SQL? I'm trying to record when new rows are inserted and when certain columns are updated, so I really just want pre_save and post_save signals. I can kind of do it with some models by using the partials defined like OnFooIDChanging() and OnFooIDChanged...

Using HTML radiobutton arrays in ASP.NET MVC

Hi, I tried to follow this but the default modelbinder let my array null on the server side. HTML: Question 1: <input name="list[0]" type="radio" value="1000" />No <input name="list[0]" type="radio" value="1001" />Yes Question 2: <input name="list[1]" type="radio" value="1002" />No ... Controller action: public ActionResult Anamne...

MVC Update Model

I'm unsure if this has been asked before but here goes. I have an MVC application with the HTML looking like this; <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EnvironmentalVandals.Controllers.MonthlyItemsFormViewModel>" %> I have in the controller the following; [...

ASP.NET MVC Model Binding

I'm having a problem with model binding. If I do use the prefix in the CopyToModelStateDictionary method, I don't get the styling or validation messages for the invalid controls. If I don't use the prefix, I get the styling and validation messages, but the page crashes if the user hasn't made a selection from a dynamically created list o...

NHibernate Validator with optional fields and optional rules?

If I have a class that holds phone numbers, called PhoneNumbers and I have a MVC view with two text entry boxes, each mapped to a PhoneNumber and I want one to be optional and one to be required, how can I achieve this with NHibernate Validator? Right now my PhoneNumber class looks like this: public class PhoneNumber { [Pattern(@"^\d{...

What namespace has JObject in json.net?

What namespace has JObject in json.net? Just installed int and can't seem to find that class? ...

How to test an ajax submition in ASP.NET MVC?

Specifically, how can I pass the static method Request.IsAjaxRequest()? I get the exception 'System.ArgumentNullException' when I try to test the following code: if (Request.IsAjaxRequest()) { return Json(data); } return View(data2); I'm using Moq. Thanks for any help. ...

Unity & Entlib on Azure

Hi Guys, I am using unity & entlib for logging and caching in my Azure webapp - I have strange problem in that the web browser takes a very long time to load. It seems there is a conflict with the web.config file but unsure what to do ? I need to wait 1-2 mins for the start page to display, sometimes it doesn't display at all - clean...

ASP.Net mvc building an xml data feed for a chart

I have to build an xml output that represents a data structured for a flex chart placed in the view. I have several options: have the controller create the xml (using data from the DB), and return it to a view that actually does nothing, since everything is ready. have the view strongly typed to the data model from the DB, and render t...

Inheriting For Multiple Shapes - ASP.NET MVC

I'm returning multiple shapes to a page and am using a ViewData class that I've created. The namespace of this class is: namespace IntranetMvcAreas.Areas.Accounts.Views.ContractsControl.ViewData which I'm not sure it correct. In the page I attempted: Inherits="System.Web.Mvc.ViewPage<ViewData.ContractsViewData>" But ViewData does...

.NET MVC - Default .onError handler for javascript?

Hi, is it possible to set a default .OnError handler for AjaxOptions in ActionLinks etc. ? ...

ASP.Net MVC And Validation Messages

I'm trying to get to grips with the Validation messages in ASP.Net MVC. I have the following view <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <h2>Create User</h2> <%= Html.Valida...

Post using JQuery to ASP.NET MVC [Authenticate]-wrapped action.

Hi, I'm trying to post with JQuery like this: $.post("NiceController/Create/", { field1: data1, field2: data2 }, function(data, textStatus) { if (data.Status) //Do something }, "json"); The problem is, that when I'm not authenticated I don't get redirected, to log-on page, because it's not a full form submit. Question is:...

Nullable<> as TModel for ViewPage

What are the possible reasons what Nullable<> types are disallowed to be passed as TModel parameter of System.Web.Mvc.ViewPage<TModel> generic? This could be handy sometimes. In ASP.NET MVC source defined what TModel should be a class: public class ViewPage<TModel> : ViewPage where TModel : class but Nullable types are value types. M...

ASP.NET MVC - Get reference to 'triggerElement' in onSuccess function?

Hi, is it possible to get a reference to the triggerElement that invoked the Ajax request in the onSuccess function? <%=Ajax.ActionLink("x", a, r, New AjaxOptions With {.OnSuccess = _ "function(context) {alert('get triggerElement reference here?');}" })%> ...

Converting classic ASP.NET custom control to MVC

Ok, this is for me a very tough challenge. We're taking our existing ASP.NET website and converting (redesigning the PL only) to MVC. Our site is very complex. But the hard part is to convert the existing custom controls to MVC equivilant. The custom controls (I am not talking about user controls) are just of course a class currently tha...