Posts

Showing posts with the label MVC

using jqGrid in an MVC View

Since MVC has gotten so popular and for a good damn reason we've lost the venerable WebForms grids. However a great replacement is the jqGrid an extension of the jQuery UI. However it does take some setup in your View and I personally find their documentation horrendous. Below is a very basic jqGrid but you need an empty table with the id that matches what's in the grid and a div that's used for the pager. You'll notice these items have to match and the div MUST be below the table for the display to work correctly. I'm using an MVC controller to get the data for the grid back. Now this won't let you add, delete, edit, etc because that gets a lot more complicated. For me this is a pretty basic grid. You need to specify a url to get data, I almost always use json as my datatype, and a GET to the server. Whatever data your return needs to be in a JSON format that matches the format in the  jsonReader section of the grid. See another post of mine on how to return ...

jqGrid get data from MVC Controller

So ever since MVC for asp.net started becoming all the rage, and for good reason! Many people have bemoaned the loss of the venerable DataGrid from WebForms. Well there are a few options out there. You have Teleriks Kendo UI suite which is great but costs money. There are a few other options but the best jqGrid a jQuery plugin. Now this grid can be a bit tricky to use. I personally find the documentation a bit short to put it politely. I've done enough grids now I'm getting the hang of it and want to share some pointers for other ASP.net MVC developers out there. Now let's assume in your View you have a nice jqGrid pointed to a controller action (I'll make another post about this as well). jqGrids are very powerful and support paging, grouping, filtering, sorting, etc. Now the bad part is you have to handle all that in your controller. This controller action will show you have to sort, page, and generally retrieve data. Now for the jqGrid to work correctly it needs ...

ASP.net MVC dynamically create and return image from Controller

I've found that I have a need to create an image dynamically (or read from a file) and return it directly from a controller. We can do that pretty easily. First add this method to a controller: public class ImageController : Controller { public void Generate() { try { //when we create a pixel we need to make it a random color Random randomGen = new Random(); Bitmap image = new Bitmap( width, height ); // create the graphics drawing tool using ( Graphics gfx = Graphics.FromImage( image ) ) // create a solid brush to draw the image, I'm using random colors using ( SolidBrush brush = new SolidBrush( Color.FromArgb( randomGen.Next( 255 ), randomGen.Next( 255 ), randomGen.Next( 255 ) ) ) ) { gfx.FillRectangle( brush, 0, 0, width, height ); ...

ASP.net MVC Ajax.BeginForm with busy icon

So I've been exploring the world of MVC and found it's pretty easy to do a postback to a controller and do it with AJAX and show a busy icon and keep the user from pressing the submit button. This is MVC 5 with the Razor rendering engine. Below is the entire section: <div id="divSendEmail"> @using ( Ajax.BeginForm( "SendEmail", "Contact", new AjaxOptions { UpdateTargetId = "result", LoadingElementId = "loading", OnBegin= "sendEmailLoad()", OnComplete= "completeSendEmailLoad()" } ) ) { <div id="loading" style="display: none; position: absolute; top: 50%; left: 50%; margin-top: -50px; margin-left: -50px; width: 100px; height: 100px;"> <img src="~/Content/images/gears_animated.gif" /> </div> <fieldset> Name: <input type="text" class="form-...