Posts

Showing posts from January, 2013

Donate

NBuilder Simple Example In C#

Nbuilder is a great tool in developing mock builders to generate data out of you application. Assuming, you don't use database for retrieving records, you can use NBuilder with LINQ capabilities to generate test data. Assuming if you have a class in your model like this: namespace MvcApplication1.Models { public class Product { public int Id { get ; set ; } public string Name { get ; set ; } public double Price { get ; set ; } public string Description { get ; set ; } } } To generate a product object using NBuilder, you may use something like this: Product product = Builder<Product> .CreateNew() .With(x => x.ProductId = productId) .And(x => x.Price = Convert.ToDouble(productId)) .And(x => x.Name = "Mushroom Can" ) .And(x => x.Description = @"Imported from New Zealand. Fresh and Juicy." ) .Build(); Cheers!

Debugging jQuery Or Javascript Code Not Working In ASP.NET MVC 2 (VS 2010)

In an application where there is internal jquery code in your MVC project, placing a breakpoint won't work when you want to enable debugging mode. After searching, a workaround has been provided by Microsoft Team. The solution is to transfer the javascript/jQuery script to an external .js file instead of embedding it in your .aspx script.Refer to the workaround. Solution: http://connect.microsoft.com/VisualStudio/feedback/details/652428/mvc-3-mvc-2-debug-ignores-javascript-breakpoints Cheers! Greg

How To Change Position A Windows Forms MessageBox in C#

Here's a tip from CODE PROJECT on positioning message box. This utilize c++ dlls. using System.Runtime.InteropServices; using System.Threading; [DllImport("user32.dll")] static extern IntPtr FindWindow(IntPtr classname, string title); // extern method: FindWindow [DllImport("user32.dll")] static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool rePaint); // extern method: MoveWindow [DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr hwnd, out Rectangle rect); // extern method: GetWindowRect void FindAndMoveMsgBox( int x, int y, bool repaint, string title) { Thread thr = new Thread(() => // create a new thread { IntPtr msgBox = IntPtr.Zero; // while there's no MessageBox, FindWindow returns IntPtr.Zero while ((msgBox = FindWindow(IntPtr.Zero, title)) == IntPtr.Zero) ; // after the while loop, msgBox is ...

ASP.NET MVC 404 Content Page Showing Or Appearing Twice

Image
Good evening gents, In handling 404 pages (pages that don't exist in the website),I encountered a problem wherein the asp.content tag/control would show twice in the page. Here's the server content code: <asp:Content ID= "Content2" ContentPlaceHolderID= "MainContent" runat= "server" > <h2>Page Not Found!</h2> <br /> Error in URL Navigation. The page you were looking for was not found. </asp:Content> And here's the content being displayed twice. The code I'm using was from a documentation/series on how to handle 404 pages. The tutorial has a controller factory that checks invalid routes and calls the base controller if a route is invalid. Below is the code: //inherit Controller Class public class BaseController : Controller { private string context; public string MyContextUrl { get { return context; } ...

The name 'ViewData' does not exist in the current context

Good Evening! In an application where I played the class diagram in visual studio by adding controller class, repository class, and service class, I encountered an error "The name 'ViewData' does not exist in the current context" in my HomeController. This is weird since the controller references System.Web.Mvc. The solution is: 1. Copy the source code in the HomeController and transfer it in a textfile for backup. 2. Delete the original HomeController. 3. Add another HomeController class 4. paste the backup code from the textfile. I guess this is a bug when using class diagrams in Visual Studio 2010. Greg

Donate