@bobnoordam

Category: ASP.NET MVC

Multiple submit buttons, and making a difference

Say we have some auto committing controls, like dropdownlist, and also a simple ‘next step’ button.How to detect a difference between the two submit events for the form ? The TYPE of the button determines it to be a form submission the NAME of the button can be used as a parameter in the controller the VALUE of the button can be used to detect the button from the controller

MVC and Linq2Sql – Adding validation

MVC supports a lot of ‘good practice’ such as dependency injection, unit testing and mocking. These things all have their place, but for some small ad-hoc coding all of that isnt’s needed. Additionaly, people crossing over to MVC get confronted in most books and documentation with a ton of good advice that at best obfuscates what is going on in the core. This post is a part of a series of posts for people crossing […]

MVC – Using icons as standard buttons and submit button

The View The following markup defines two images as buttons. Standard GET behevaiour is the simple one of the two, it isnt anything else then an image wrapped into a link. The @Url.Action calls the required action on the controller. The submit button is an actual button. The mini CSS snippet makes sure we dont get the default gray background of the button, and only the actual image. The end result is that the two […]

DevExpress DateEdit (Date Picker) model binding in MVC

This is the absolute minimum you need to use model binding with the DevExpress date picker control. The important part is that the name setting on the control must be the same as the field name you use to store the picked value in. ViewModel using System; namespace DXWebSample.ViewModels { public class DemoViewModel { public DateTime PickedValue { get; set; } } } View @model DXWebSample.ViewModels.DemoViewModel <h2>Date Picker demo</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary() <p> […]

MVC – Return a file download from an MVC controller

#1, Return a byte[] as a download Use case; You have an in memory byte[] array containing something you want to offer as a a download. (For example an excel sheet) string fileName = “something.xls”; return File(result, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); #2 Return a text file as a download Here we trick the browser to offering the file as a download by claiming the content is a binary stream. The used overload now takes the filehandle as […]

MVC and Linq2Sql – Getting your data in and out of the model

MVC supports a lot of ‘good practice’ such as dependency injection, unit testing and mocking. These things all have their place, but for some small ad-hoc coding all of that isnt’s needed. Additionaly, people crossing over to MVC get confornted in most books and documentation with a ton of good advice that at best obfuscates what is going on in the core. This post is a part of a series of posts for people crossing […]

MVC Webgrid basics – Simple grid with paging and sorting and selection

The Webgrid helper This series of documents outlines basic usage of the webgrid helper, and how to implement paging, sorting and selection comparable to the Webforms GridView control. You can download the final iteration of the solution file here: MVC-Sample-PagingSorting.zip Basic usage The controller class below retrieves the products table from the NorthWind demo database, and passes them into the view. Note that there are aboslutely no provisions for sorting and paging in the code […]

MVC File upload

The view part Our view defines a multipart form to enable us to post both files and other model/form fields. Once a file is uploaded the controller will set the ViewBag.UploadStatus to a confirmation message, causing the upload part to disappear and the confirmation to appear. The multipart declaration in the form is required to be able to post binary data The submit button has a name so we can detect multiple submitbuttons and take […]

MVC – Making a popup editor element in asp.net mvc

This document demonstrates a way to present the viewer with a list of records, and use a popup window to edit the data. This is acomplished in MVC by using a viewmodel that contains the record list – and at the same time provides the data fields of an optional selected record. The popup by itsself is rendered with jQuery and the WEBFW css framework. (all included in the downloadable solution at the end). Our […]