Posts

Showing posts from November, 2017

Donate

Display Images Using Generic Handler In ASP.NET MVC

Image
There are several options on how to show images in ASP.NET MVC. One of them is using a generic handler. This method was applied since the early days of ASP.NET Webforms and still can be used with recent frameworks. The class below will render the images on the page by calling the ProcessRequest method which will then get the image from datasources such as database and file system and return it as a Bitmap object. public class ImageHandler : IHttpHandler { private OnlineShoppingDBEntities shoppingContext; public ImageHandler () { shoppingContext = new OnlineShoppingDBEntities(); } public void ProcessRequest (HttpContext context) { if (context.Request.QueryString[ "ProductID" ] != null ) { Product product = shoppingContext.Products.Find(Convert.ToInt32(context.Request.QueryString[ "ProductID" ])); if (product != null ) { Byte[] bytes = product.Image; int height = 0 ; int width = 0 ; height = 100 ; width = 10

Add Glyphicon To Ajax.ActionLink() In ASP.NET MVC

Image
Good evening! Adding a Bootstrap glyphicon to Ajax.ActionLink() helper is similar with Html.ActionLink() except that when the linkText parameter of the helper is empty, it will cause an Ajax issue and an Internal Server Error will be thrown from the browser. If you're going to integrate glyphicons on Ajax.ActionLink() helper and exclude the linkText property, supply that parameter with space instead of empty string so as not to cause jQuery or Ajax issues. @Ajax.ActionLink( " " , "DeleteComment" , "Home" , new { id = comment.CommentID }, new AjaxOptions { OnBegin = "return confirm('Are you sure you want to delete this comment?');" , InsertionMode = InsertionMode.Replace, UpdateTargetId = "event-details-" + Model.Id, HttpMethod = "GET" , }, new { @class = "commentDelete glyphicon glyphicon-trash" }); linkText i

Invalid nested tag div found, expected closing tag input

Hello all, I've been experimenting on how to print html document using the said 3rd party software called iTextSharp . iTextSharp is a popular tool and has several examples on the internet regarding integration to the project and occurring issues. One of the issue I encountered is Invalid nested div tag and is expecting a closing tag input . As I trace back my html source, the tags are well-formed except that they are self closing tags such as <input>, <hr>, <img>, <br> or the like. These tags when passed to an action method as string are not properly closed and thus an issue is thrown by iTextSharp's XMLWorkerHelper's ParseXHtml() method. <img src= "~/Images/success.png" /> <input type= "hidden" name= "OrderStatusHTML" /> <input type= "submit" id= "btnSubmit" value= "Export to PDF" class= "btn btn-success" /> The solution I came up with is to fi

Add Glyphicon To Html.ActionLink() In ASP.NET MVC

Image
Hello, Here's how to integrate glyphicon to Html.ActionLink() helper in ASP.NET MVC. The code below will display the glyphicon shopping cart right after the text Checkout of the anchor element. @Html.ActionLink( "Checkout" , "Index" , "Home" , null , new { @class = "btn btn-info glyphicon glyphicon-shopping-cart" }) In order to add the glyphicon before the text of the anchor element, use @Url.Action() instead. <a href= "@Url.Action(" Index ", " Checkout ")" class= "btn btn-info" > <span class= "glyphicon glyphicon-shopping-cart" ></span>Checkout </a> Output:

Formatting Numbers Using toLocaleString() In JavaScript

I've been using a JavaScript 3rd party library to format numbers with comma and decimal place(s). The JavaScript library called NumberFormatter was introduced to me by my developer with exceptional skills in front-end programming. Due to simplicity sake, I'm exploring options if this can be achieved using an existing JavaScript function instead of using the existing 3rd party app. After doing some research, I found an answer here: How to use toLocaleString() and tofixed(2) in javascript which is to use toLocaleString() by setting the options minimumFractionDigits and maximumFractionDigits to 2. Number .prototype.toLocaleFixed = function (n) { return this .toLocaleString( undefined , { minimumFractionDigits : n, maximumFractionDigits : n }); }; Sample usage: var result = parseFloat (amount).toLocaleFixed( 2 )

Donate