May 1, 2013 at 2:59 PM
—
Madestro
I recently decided to play with Bootstrap, a front-end framework for creating websites that are responsive to the type of device used to access them.
I was following an article I found in .NET Curry and everything was going well. For anyone new to Bootstrap, here is a quick overview of the steps to add Bootstrap to an ASP.NET MVC4 application:
- Add Bootstrap NUGET package to MVC4 application
- Update jQuery to the required version
- Add Bootstrap bundles in BundleConfig.cs
- Modify _layout.cshtml to include Bootstrap scripts and styles
- Modify _layout.cshtml with the wireframe of your new Bootstrap design
- Modify your pages based on Bootstrap
(Read the full article for details)
Strangely enough, the styles were not being applied. I did everything the article said!... why is it not working?...
Further examination revealed the Bootstrap scripts and CSS was not being outputted to the page.
After Googling for a while, I found the answer in StackOverflow.
It turns out the BundleCollection class (passed on as a parameter to the BundleConfig class from the Global.asax call) has an IgnoreList property which is an instance of the IgnoreList class that defines items or patterns to ignore.
Conveniently (or not so) enough, it ignores the ".min" pattern.
The solutions:
- Remove the .min from the script and style paths added in the BundleConfig.cs class, OR
- Call the Clear() method of the IgnoreList instance in order to remove the filters:
- bundles.IgnoreList.Clear();
This will cause your Bootstrap scripts and styles to render as they should.
One more note for those of you getting started with Bootstrap:
Applying the NUGET package only adds the files needed to run bootstrap. It won't magically change your layout and/or pages. Once you get Bootstrap running, go get yourself a page design and/or theme and modify your pages accordingly.
044acb41-3809-4568-b105-df4c682775e7|0|.0
Posted in: ASP.NET MVC
Tags:
January 31, 2013 at 4:18 PM
—
Madestro
I recently started working with MVC4. After (literally) cutting and pasting code from some other application I had worked on which used MVC3, I found my Ajax calls where no longer working.
It took me about three hours of research to figure out what the issue was.
The JQuery libraries that are used for Ajax calls are loaded in a different manner now. In the past, you would include them one by one in your _layout file. With the new version, you need to introduce the right "bundle".
If you look at the code generated by the VS template, you will see two calls that load stuff for you:
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
What you need to do is add the following two lines of code in order to load the JQuery includes:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
What's happening under the scenes is that there is now a new Bundle and Minification Framework in place. If you look at your App_Start folder, you will notice a file called BundleConfig.cs. This file contains bundle definitions that are used to load resources. You can read more about it here.
The bundle in question here is defined as follows:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
Once these two files are loaded, your Ajax calls should start working again.
Hopefully this post will save you some Google time... you can find the source that solved my issue here.
266e351c-2925-4673-ab25-2bfbccaa5b0c|0|.0
Posted in: ASP.NET MVC
Tags:
January 28, 2013 at 1:44 PM
—
Madestro
Back in April, Google updated their algorithms so that pages overloaded with relevant keywords actually rank lower. Now they are officially warning against this practice in their guidelines.
On top of that, encrypted search (when you get the "not provided" keyword entry in the reports) has essentially made keyword reporting unreliable.
If you are interested in the details, you can read the full article from Starpoint Marketing here.
That's right. Finally, no more meaningless garbage designed to generate more hits!
More meaningful content, more elegant content. That's the way it should be.
576b18a7-8893-48e4-ae6e-21e1574942e3|0|.0
Posted in: SEO
Tags:
April 3, 2012 at 10:14 AM
—
Madestro
It's not very obvious to the non-db-admin type but you can't just override an identity value in a table, even if you set identity_insert ON.
What you need to do instead is:
- Turn identity_insert ON
- Delete the record you need to change
- Insert it again with the desired identity value
- Turn identity_insert OFF
Here is the code snippet:
SET IDENTITY_INSERT YOUR_TABLE ON
DELETE FROM YOUR_TABLE WHERE YOUR_IDENTITY_FIELD = THE_ID_YOU_NEED_TO_CHANGE
INSERT INTO YOUR_TABLE (YOUR_IDENTITY_FIELD, ...[other fields]) VALUES (THE_NEW_ID, ...[other fields])
SET IDENTITY_INSERT YOUR_TABLE OFF
75215c6c-b9b0-422f-b27f-a13f296cf1d7|0|.0
Posted in: Databases
Tags:
February 28, 2012 at 3:37 PM
—
Madestro
I have been coding for a number of years now and most of the code I have come across (I would say 98%, no exaggeration) is in Allman's format.
For those of you who are not familiar with these bracket styles (or maybe you are but don't associate the name with the style), Allman's format is about putting the brackets each in its own line:
if (a == b)
{
return true;
}
else
{
return false;
}
While K&R is about putting the bracket at the end of the control statement:
if( a == b) {
return true;
} else {
return false;
}
I personally like Allman's. In my opinion it's totally easier to read. This of course is my personal preference. Either method [obviously] works and produces the same result, but I do find having to read K&R style annoying. So annoying in fact that I decided to write this post... :-)
Thoughts?
February 23, 2012 at 4:47 PM
—
Madestro
I was working on something and needed to refer to the ASP.NET MVC lifecycle so I went out there and found the following information which I have compiled for your benefit:
Overview of the Lifecycle Steps
There are five main steps that happen when you make a request from an ASP.NET MVC website:
1. The RouteTable is Created
This first step happens only once when an ASP.NET application first starts. The RouteTable maps URLs to handlers.
2. The UrlRoutingModule Intercepts the Request
This second step happens whenever you make a request. The UrlRoutingModule intercepts every request and creates and executes the right handler.
3. The MvcHandler Executes
The MvcHandler creates a controller, passes the controller a ControllerContext, and executes the controller.
4. The Controller Executes
The controller determines which controller method to execute, builds a list of parameters, and executes the method.
5. The RenderView Method is Called
Typically, a controller method calls RenderView() to render content back to the browser. The Controller.RenderView() method delegates its work to a particular ViewEngine
Source: http://stackoverflow.com/questions/2355139/what-is-the-lifetime-of-a-asp-net-mvc-controller
I also found a chart by Steve Sanderson you can print and keep around your desk:
http://blog.stevensanderson.com/2009/10/08/aspnet-mvc-learning-resource-request-handling-pipeline-poster/
dc8b5a49-d577-4058-8f68-55e81c814876|0|.0
Posted in: ASP.NET MVC
Tags:
January 30, 2012 at 2:38 PM
—
Madestro
So I was working on an ASP.NET MVC application and stumbled upon a little situation that was driving me nuts. I had an action link which used a confirmation message box that would allow the user to delete a record. The code was straight forward but for some reason the action would not fire on the controller.
After trying a few things I realized I was using some boiler plate code that provided standard handlers for the events:
new AjaxOptions() { Confirm = "Are you sure you want to delete this record from the system?", UpdateTargetId = "Results", HttpMethod = "POST", LoadingElementId = "LoadingContainer", OnSuccess = "Ajax_OnSuccess", OnFailure = "Ajax_OnFailure", OnBegin = "Ajax_OnBegin", OnComplete = "Ajax_OnComplete" }
(Scroll to the right on the code line, notice the "Ajax_" event handlers)
The issue turned out to be that I had forgotten to include the script file with these functions into my page. Apparently, if you provide method names but do not provide the implementation, it breaks the call to the action.
I hope this saves someone else some time...
2dc93a57-5c54-4c9c-bd43-ec47e53916b1|0|.0
Posted in: ASP.NET MVC
Tags:
January 13, 2012 at 1:38 PM
—
Madestro
I was trying to connect to my hosted database with SQL Management Studio 2008 when I ran into an issue. I was able to connect fine using my database credentials but when I attempted to expand the Databases node, Object Explorer just hung trying to load the list of databases. I could run queries and everything, but the database list node would not load.
The issue turned out to be the amount of data being loaded by Object Explorer. Because my provider hosts a lot of databases, Object Explorer was taking an unusually long time loading all the information for every database in the list.
The solution to this issue is:
- Login to any database server
- Select the "Databases" node in Object Explorer
- In the top menu, select "View -> Object Explorer Details"
- When the "Object Explorer Details" tab opens, right click on any of the headers (.e.g Name, Owner, etc) to get a list of columns to display
- Uncheck all the columns you don't need. I personally keep only the Name and Owner columns checked
- Restart SQL Management Studio
Log in to your server again and the databases should be displayed normally.
Here is the link to the original post I found in order to troubleshoot this issue: http://stackoverflow.com/questions/2013923/expanding-list-of-databases-in-sql-server-2008-management-studio-takes-longer-th
591c1245-b9a2-493a-ace1-7df1bae54935|0|.0
Posted in: Databases
Tags:
January 12, 2012 at 10:34 AM
—
Madestro
Well, it had to happen sometime. I finally got my own blog up and running!
Welcome and thanks for stopping by!
I must say, I am impressed with what the BlogEngine.NET guys have done. Their blog engine is very easy to setup. I was up and running in no time so special thanks to them. If you are looking for blog software, please visit their page at http://www.dotnetblogengine.net.