March 2010

 Not only does MVC support server-side validation, client-side validation is a possibility too.  Below is a sample form that sets up validation using client-side javascript.  These client-side features are made available from the MicrosoftMvcValidation.js file.  Take a look at the sample form with validation below. <% Html.EnableClientValidation(); %> <% Html.BeginForm(); %> <%= Html.ValidationSummary(“The following errors […]

We are about to talk about client validation soon, but if you already know about it, read on; if not, wait until my next post and come back to this one :-).  I’m writing this now because I just found it.  If you use client validation, it’s important to ensure you enable client validation before the […]

ASP.NET MVC 1 had features built in that allowed you to validate content on the server-side, by specifying the elements to listen to validations for.  These features have been enhanced so that you can use a lambda to specify the field to validate.  Below is an illustration of these new features. <% Html.BeginForm(); %> <%= Html.ValidationSummary(“The […]

    <p> Ajax Custom</p> <p>  <div id=”customresponse”></div>  <% using (Ajax.BeginForm(“AjaxCustom”, new AjaxOptions { UpdateTargetId = “customresponse” })) { %>      <div>   Name: <%= Html.TextBox(“CustomName”)%>  </div>  <div>   Value: <%= Html.TextBox(“CustomValue”)%>  </div>      <input type=”submit” value=”save” />    <% } %></p>   [HttpGet, ChildActionOnly]public ActionResult AjaxCustom(){ return PartialView();} [HttpPost]public ActionResult AjaxCustom(FormCollection post){ return Content(“Success”); //return PartialView();} public ActionResult AjaxIndex(){ return View();}

    <p> Main Action</p> <% Html.BeginForm(); %>  <div>  Name: <%= Html.TextBox(“IndexName”) %> </div> <div>  Value: <%= Html.TextBox(“IndexValue”) %> </div>  <input type=”submit” value=”save” /> <% Html.EndForm(); %> <%= Html.Action(“Custom”, new { title = “Test Title” }).ToHtmlString()%>   [HttpGet, ChildActionOnly]public ActionResult Custom(){ return PartialView();} [HttpPost]public ActionResult Custom(FormCollection form){ return PartialView();} public ActionResult Index(){ return View();}       <p> Main Action</p> <form action=”/RenderingActions” method=”post”>  <div>  Name: <input id=”IndexName” name=”IndexName” […]

In ASP.NET web forms, anytime an element within the form post contains an HTML tag (such as a <div> or any other tag), the input that’s posted back to the server is validated, and an exception thrown, if that post contains any HTML tags within it.  This is request validation, and in web forms it can […]

ASP.NET MVC 2 has provided a lot more options for displaying the data to the end user within your views.  Here are a few of the options you have: Html.DisplayFor(i => i.FirstName) – DisplayFor renders the value of a property directly to the browser.  In this example, the FirstName property returns a string, which gets rendered.  […]

You may or may not have heard that ASP.NET MVC 2 has been released not too long ago.  There are quite a few changes that come with ASP.NET MVC 2.  In this article, I’m going to talk about some of the attribute changes related to MVC 2 now available to us: ChildActionOnly – This attribute […]

The ASP.NET Enterprise Application Development book, which is part of the Problem/Design/Solution series, is setup as a book that illustrates the problem first, then moves to the design (and looks at various design possibilities), and finishes up with the solution to implement.  The sample project for this book is a time-tracking opportunity, an application to […]