Geeks With Blogs
Doug.Instance Improving the world one post at a time MVC ASP.Net MVC 2
Simple MVC Imperative Validation
After looking at FluentValidation, I decided that most of what I needed was a way to do server-side validation of more complicated rules. While this is something FluentValidation does, it seemed like more than I needed so I set out to create a simple extension method to do what I needed. While it is still not necessarily perfect, it is simple and works. 1: public static void Validate<T, TResult>(this Controller controller, T model, Expression<Func<T, TResult>> expression, Func<TResult, ......

Posted On Wednesday, December 26, 2012 3:59 PM

Two Best SharePoint Utility Methods Ever Written
SharePoint is very handy as a repository for data. There are things (particularly in the intranet world) which really don't need a dedicated database or application and SharePoint is a great enabler. However, if you want to build a lightweight, standards-friendly web page using SharePoint, you have a challenge ahead of you. Here is the problem I was trying to solve: I have a SharePoint site that serves as the home page for an organization. I needed to be able to pull in various content from other ......

Posted On Friday, April 20, 2012 10:15 AM

The Enemy of My Friend Writes Bad MVC Controller Actions (Microsoft)
Recommendation: Don't use the same action names for get and (Ajax) post.I am always amazed at how bad Microsoft's code examples are. Code generated using the default templates in Visual Studio is not much better. To find out, create an empty project (pick your favorite type) and run static code analysis or FxCop and see how many warnings you see. For some real fun try running StyleCop. The default templates (and therefore commonly-used standard practices) are also not very good in my opinion. Consider ......

Posted On Thursday, February 16, 2012 11:29 PM

Key to Strongly-Typed HtmlHelper Extensions in ASP.Net MVC2
While you can do most common tasks by simply passing expressions through to existing HtmlHelper extension methods, you may stumble on something where you want to evaluate the lambda expression on your own. While this may seem daunting at first, the MS folks have made it pretty simple. All you have to do is this: ModelMetadata modelMetaData = ModelMetadata.FromLambdaExp... htmlHelper.ViewData); This assumes that htmlHelper and epxression are parameters of your extension method which ......

Posted On Friday, March 25, 2011 10:23 AM

Problem: DropDownList Always Posts Blank Value in ASP.Net MVC 2
Consider the following code:<%= Html.DropDownList("State", new SelectList(new string[] { "","AK","AL","AR","AS","AZ"... "IL","IN","KS","KY","LA","M... "OH","OK","OR","PA","PR","P... %> Simple enough, right? Display a dropdown list with a value for each state. There is only one problem. The resulting ......

Posted On Tuesday, February 7, 2012 10:08 AM

Custom Model Binding of IEnumerable Properties in ASP.Net MVC 2
MVC 2 provides a GREAT feature for dealing with enumerable types. Let's say you have an object with a parent/child relationship and you want to allow users to modify multiple children at the same time. You can simply use the following syntax for any indexed enumerables (arrays, generic lists, etc.) and then your values will bind to your enumerable model properties. 1: <% using (Html.BeginForm("TestModelP... "Home"))2: { %>3: <table>4: <tr><th>ID</... ......

Posted On Tuesday, November 29, 2011 5:29 PM

Another Benefit of Asynchronous Processing of ASP.Net MVC Results
Most people who are really into ASP.Net MVC probably enjoy its test-driven nature or "unit-testability". This is a key benefit of the asynchronous model used by the MVC framework when action results are returned. Another benefit of this is in memory management. I am working on creating a large document which is to be available both online and offline and consists of several hundred (potentialy more than a thousand) items. The items are stored in a tree structure where each item has children and children ......

Posted On Tuesday, September 27, 2011 9:13 PM

Simple MVC 2 Pager
I wrote a simple pager AjaxHelper extension. You can convert this to an HtmlExtension method by just removing the AjaxOptions and swapping out the AjaxHelper with HtmlHelper. This assumes that your parameter for the page name is "Page". 1: public static string Pager(this AjaxHelper ajaxHelper, int page, int pageSize, int count, int pages, string actionName, string controllerName, object routData, AjaxOptions ajaxOptions) 2: { 3: StringBuilder sb = new StringBuilder(); 4: int pageCount = count / pageSize ......

Posted On Thursday, September 22, 2011 5:44 AM

Redirecting from a Partial View the "Right" Way in ASP.Net MVC 2
I am a firm believer that, regardless of the framework you use, if the framework is good it provides you all of the things you need. I believe ASP.Net MVC 2 is good and therefore provides me everything I need. This means I don't need to write a significant amount of custom UI code (jQuery, MVC Ajax, etc.) to do things that should be considered "standard". One of these pretty standard things submitting a form via Ajax. MVC provides for this very well with Ajax.BeginForm. The contents of the form are ......

Posted On Friday, August 5, 2011 6:52 PM

Charts in ASP.Net MVC 2 With Drill-Down!
I have seen several posts on how to use the ASP.Net chart controls with MVC and they all involved some sort of hybrid web forms approach. I have a simple solution which is 100% MVC. Here is a summary of the process: Create an action to render the chart. Create an action to render the image map. Use a normal IMG tag to render the chart image. Use Html.RenderAction to render the image map. The most simple implementation without drill-down would look something like this: public ActionResult Chart(int? ......

Posted On Sunday, January 23, 2011 10:19 PM

Copyright © Doug Lampe | Powered by: GeeksWithBlogs.net