asp.net-mvc

Custom Model Binder - How to revalidate

Hi there, I'm using ASP.NET MVC 2 and want to figure out how to re-trigger the validation on my model after it has been populated using a custom binder. So, I start with a couple of EF classes which are associated, Booking and Traveller (each booking can have one or more travellers) Here's the buddy class I'm using to place balidation...

try catch with mail problem

Hello Lets say I have something like this: public ActionResult Test(SomeModel m) { try { _db.SaveModel(m); SendMailToUser(m); RedirectToRoute("Something"); } catch { return View(); } } And I got problems with howto deal with this if "SendMailToUser" fails. Model gets saved to...

ASP.NET MVC: having one model for all views

I like the way model binding in django works: you send stuff that you need in a Json-like way: 'param1': val, 'param2': val In ASP.NET MVC you can't do it primarily because C# is a static language. You can use ViewData but it's ugly and not recommended. So I had to create dozens of ViewModels for every view: IndexViewModel, AboutView...

localize data annotations default messages ([Required] [StringLength] etc.)

if I decorate the properties of my ViewModels with attributes like this: public class Vm { [Required] [StringLength(35)] public string Name {get;set;} } I am going to get english validation messages: "this field is required" "The field Name must be a string with a maximum length of 35" how could I translate them ? ...

How to use a ShortDate string format with Html.TextBoxFor

Using Entity Framework with MVC2, I have a series of date textboxes, that I want to display data from the model in a short date format, but I have to use Html.TextBoxFor in order for the update code to work (Having tried using HTML.Textbox the data never gets saved to the model). <%: Html.TextBoxFor(model => model.Item.Date, String.For...

Setting expiration on cached entities with SharedCache and Nhibernate

Hi guys, I have an MVC webapp that I'm putting together now. A second app publishes data to a database which my webapp reads from. I am using SharedCache as a cache provider for my NHibernate and I wish to assign "expirations" to my entities (so I can guarentee a level of freshness of the data) - and knowing that some entities are rare...

Is it applicable to place methods inside ASP.NET MVC views?

The current code of one of the views in my project is a large, monolithic one and I just want to organize it. Is it just fine to place methods inside my ASP.NET MVC view? ...

Problem with MvcSiteMapProvider and dynamicNodeProvider

Hi I have add the provider in my web config as below: <add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Sitemap/SiteMap.sitemap" securityTrimmingEnabled="true" enableLocalization="true" scanAssembliesForSit...

asp.net mvc - Elmah and partial view

I have a page that contains multiple div's. Action on one div changes the content of other div. Each div loads a partial view from controller. For example- a div for "Search" and another div for "SearchResult". "Search" div contains couple of fields and a button. On click of this button a controller method is invoked asynchronously usi...

Hide a row in a table and display it again?

I use a foreach loop inside ASP.NET MVC View page. For each element of the collection that foreach operates on I create two rows - one for display, one for edit. I want to hide the edit row and only display it later depending on user action. If I hide the edit rows with display: none, then jQuery's show() method cannot redisplay it agai...

Asp.net file dialog set default folder

Is there any way to do this? I thought I'd find hundreds of results on google for this but not really finding anything. I want to set it to a location either on the web server or on a mapped networked drive somewhere. I'm talking about with <input type="file" ... /> to clarify. ...

Custom javascript validation

Hi guys, Is there any way to show custom input validation message through javascript? I have javascript validation method innvoked with Form.Submit, so if validation goes wrong, I'd like to have a custom text next to the field I have validated (similar as ASP.NET MVC 2 validation summary). Regards ...

Stackoverflow like pagination helper in asp.net mvc

Is there any pagination helper like stackoverflow in asp.net mvc? ...

Char to Enum in Index View in MVC

I have HelpBoxes in my DB. those are messages people get on the site. each message has a receiver. either it's an organisation or a user, or both. I have this Enum public enum Ontvangers { All = 'A', Organisation = 'I', User = 'D' } now in my index view public ActionResult Index(string schooljaarp...

Form Authentication IsOnline method does not retrieve the correct status

Hello, I am using Form Authentication in an ASP.NET MVC project. When the current user click on the Exit link the code execute an action that does in sequence: System.Web.Security.FormsAuthentication.SignOut(); Session.Abandon(); The second call is not properly needed because I am not using session at all. The problem is that if I...

Adding dynamic parameters with Html.BeginForm and jQuery submit

// html <% using (Html.BeginForm("MyAction", "MyController", new { id = ViewContext.RouteData.Values["id"] }, FormMethod.Post, new { enctype = "multipart/form-data", class="myForm" })) { %> <input type="file" name="blah" /> <% } %> // script $container.find('.myButton')....

Sending an unknown object to a RenderPartial in MVC

this is my renderparial <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %> <a href='<%= Url.Action("Edit", new {id=Model.ID}) %>'> <img src="<%= Url.Content("~/img/pencil.png") %>" alt="Edit" width="16" /></a> I basically want to call it in this way: <% Html.RenderPartial("edit", new...

Dynamically Constructing Lists on Client-side on ASP.Net MVC2

Hi, I need to create a list of dynamically generated entries on the client as the user can control how many entries he needs pressing a + symbol. Functionality in some sense is similar to the "Google Finance Stock Screener" add criteria. In code I have a model that looks like this: public class Model { public List<string> DynamicLi...

ASP.NET MVC AjaxForm onFailure - How to display error?

I have an Ajax Form that looks like this: <% using (Ajax.BeginForm("Update", new AjaxOptions { UpdateTargetId = "message", InsertionMode = InsertionMode.Replace, OnSuccess = "success", OnFailure = "error" })) { %> I can get "error" to run on a failure but i would like to alert the error message. How can i get this information...

Renderpartial in subfolder of Shared folder. How to make MVC find it?

Short but simple? I have an edit.ascx is in the shared folder. I call it like this: <% Html.RenderPartial("edit", item.hlpb_ID); %> If I put it in a subfolder, it cant find the file, how to fix that? ...