Posts

Showing posts from February, 2016

Donate

Castle.MicroKernel.Registration.AllTypes' is obsolete in ASP.NET MVC 5

In the event that you'll be referencing Castle Windsor 3.3.0 and incorporate the IOC container in your project, you will encounter the error stated by the title of this post. This happens when you use register the controllers to the IOC container using AllTypes class. 1 2 3 4 container.Register(AllTypes.FromThisAssembly() .Pick().If(t => t.Name.EndsWith( "Controller" )) .Configure(configurer => configurer.Named(configurer.Implementation.Name)) .LifestylePerWebRequest()); This class has been deprecated in the recent versions of Castle Windsor. The solution is to update the Register method and replace AllTypes with Castle.MicroKernel.Registration.Classes . 1 2 3 4 container.Register(Classes.FromThisAssembly() .Pick().If(t=> t.Name.EndsWith( "Controller" )) .Configure(configurer => configurer.Named(configurer.Implementation.Name)) .LifestylePerWebRequest());

Read JSON Array Using Json.NET JsonTextReader In C#

Image
Hello, Here's how to read or parse JSON array using Json.NET JsonTextReader class in C#.Given the sample JSON data below, you might wanna parse the information provided and retrieve the name property of a JSON Array StartObject and add it to a list box control. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 18

ASP.NET MVC 5 Client Side Form Validation Using jQuery and Bootstrap

Image
Hello, Here's a VB.NET example on how to perform form validation using jQuery and Bootstrap without Model class. Validation is performed purely on the client side. The steps are explained in detail at VBForums codebank ASP.NET MVC 5 Form Validation using jQuery and Bootstrap without Model class and the source code can be downloaded in github MVCFormValidationJQueryValidateVB . Screenshots: That's it.. :-)

ASP.NET MVC 5 jQuery Validation Form.Validate() Method In External JavaScript File Not Firing

I have an external JavaScript file that validates a form using form.validate() of jQuery validation plugin. $( function () { $( "#frmInput" ).validate({ submitHandler: function (form) { //submit once validation rules are met form.submit(); }, .....other codes here }); }); When integrating it in an MVC 5 application, the validate event does not trigger. I have checked if there are errors using the Chrome developer tools and Firefox but to no avail there is none. The solution I discovered was to change the BundleConfig.cs file and the order of scripts rendering in _Layout.cshtml. After that, form validation now works. Steps: 1. Change BundleConfig.cs codes //change code in BundleConfig.cs From:   bundles.Add( new ScriptBundle( "~/bundles/jqueryval" ) .Include( "~/Scripts/jquery.validate*" ));   //To: (individual bundling of validate and unobtrusive js files)   bundles.

Large Spacing Between Form Controls In ASP.NET MVC 5 VB.NET Project

As I was converting a registration form from MVC 5 C# website to VB.NET MVC 5, I've noticed that in VB.NET the div elements with form-group class have different spacing in between compared with the former project. I've doubled checked and compared Site.css and my custom css files and all styles are the same. Luckily, I found out that MVC 5 VB.NET project includes the older version of Bootstrap that is version 3.0. So, replacing the old bootstrap files in VB.NET project with bootstrap.min.css and bootstrap.css version 3.3.6 corrected the issue.

ASP.NET MVC 5 Client-Side Remote Validation Using jQuery

Image
When integrating jQuery validation in ASP.NET MVC, here's how to apply client-side remote validation using javascript code. Below are the snippets and screenshots. Make sure to render the jquery.validate.min.js file in your View or Layout. Email HTML Markup: 1 2 3 4 5 6 7 <div class= "form-group has-feedback" > <label for= "email" class= "control-label col-md-3" >Email Address:</label> <div class= "col-md-9" > <input type= "email" name= "email" id= "email" class= "form-control" placeholder= "Enter email" /> <span class= "glyphicon form-control-feedback" id= "email1" ></span> </div> </div> Custom Javascript Validation Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 $( function () { $( "#frmInput" ).validate({ sub

ASP.NET MVC WebGrid In Partial View Redirects To Blank Page During Pagination

Image
Hello, I've created an ASP.NET MVC website that loads a partial view with a WebGrid control on ajax call. When I tested navigating to next record set, the WebGrid performs a postback and then redirects to a blank page. Not only that, the WebGrid control also lost it's css style. After doing some research on it's properties, I basically encountered a property called ajaxUpdateContainerId . After including that property in the WebGrid control, the pagination works fine and does not redirect to a blank page. Original Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 @{ var grid = new WebGrid( canPage: true, canSort: true, rowsPerPage: 10); grid.Bind(Model.AddressList, rowCount: Model.AddressList.ToList().Count); grid.Pager(WebGridPagerModes.NextPrevious); @grid.GetHtml(tableStyle: "webGrid", htmlAttributes: new { id = "grid" }, headerStyle: "hea

LINQ To SQL In Operator With Subquery

Given the following sql statement below using In operator with subquery as it's argument, I need to convert this to LINQ statement. SELECT [CountryRegionCode] ,[Name] ,[ModifiedDate] FROM [AdventureWorks2012].[Person].[CountryRegion] where CountryRegionCode in ( select distinct [CountryRegionCode] from [AdventureWorks2012].[Person].StateProvince) After doing some readings on LINQ documentation, I found it's equivalent LINQ code using let . model.CountryRegionsList = ( from country in _context.CountryRegions let subQuery = ( from stateprovince in _context.StateProvinces select stateprovince.CountryRegionCode). Distinct () where subQuery. Contains (country.CountryRegionCode) select country).ToList();

ASP.NET Trigger Onchange Event Of DropDownList Inside GridView Using jQuery

Image
There was a question in a forum if how can we trigger an onchange event of a DropDownList control inside a GridView template field. This time using unobtrusive approach. So in order to understand a bit further, the GridView control when rendered to the browser becomes a table element while DropDownList becomes a Select control. So, to trigger the event we need to traverse the GridView control then find the Select control and attach a change event. Here's a solution using jQuery. HTML Markup: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <asp:GridView ID= "gvItem" runat= "server" AutoGenerateColumns= "False" > <Columns> <asp:BoundField DataField= "ID" HeaderText= "ID" /> <asp:BoundField DataField= "ProductName" HeaderText= "ProductName" /> <asp:TemplateField HeaderText= "Time Slot" > <

ASP.NET MVC 5 Client-Side Form Validation Using jQuery And Bootstrap With Model Class

Image
Here's a simple client side validation in ASP.NET MVC 5. By default, the application's unobtrusive validation has been set to true in web.config file. For this demo, I did not include a saving process to database. I just added a simple view to indicate a success if the model passed to the controller is valid. See files and screenshots below: Registration.cs (This should be created inside the Model folder) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 public class Registration { [Required(ErrorMessage = "You must provide your first name")] [Display(Name = "First Name")] public string FirstName { get ; set ; } [Required(ErrorMessage = "You must provide your last name")] [Display(Name = "Last Name")] public string LastName { get ; set ; } [Required(ErrorMessage = "You must provide your middle name")]

Donate