Category Archives: .NET

Set menu item to Active in MVC with BootStrap

Recent I start working on MVC with BootStrap for building the great Web UI. I am building a menu with several menu items and found out that it is not setting as “active” in the class of the item when a page is loaded.

BootStrap_menu_01

By default the MVC template doesn’t add the active class to the “li” item in the menu. So I have to add the class=”active” to the “li” to indicate the active menu item.

BootStrap_menu_02

Above is the code that is used for the actual menu that create the menu in the first screenshot. if you look at line 8, you will see the class=”active”, this is what makes the active menu item. In order for us to do this, we need to know what page is currently loaded and then apply the active class css to the corresponding “li” element. The best way to do this, is to create a HTML helper to handle this for us.

Now, let’s try to create a new folder in the project and called “Helpers”. Then add a new class named “HtmlHelpers.cs” (from my sample, I used KenLinHtmlHelpers). here we could create an extension method of the HtmlHelpers method. We do this by creating a static class.

BootStrap_menu_03

As you can see, I have created 2 method, IsActive and IsActiveController. The only difference is, do you want to take Action into one of the input parameter. If you want to set class is active whenever it is in the specific controller, you could use IsActiveController. Otherwise, you may use IsActive if you want the active class only in exactly the specified Action and Controller. Please also note that, I am letting the activeClass and inActiveClass input as optional with a default value.

Now we could update our cshtml as below,

BootStrap_menu_04

Look carefully on each “li” item now. There is a new HtmlHelper method to check and show if it is the active controller.  Please also look carefully, I have also called the method in line 9, for the parents of the dropdown Menu.

NOTE: You have to reference the class in the top of the view page that you are using the IsActive or IsActiveController method in. Just add the code as line 1 of the above screenshot.

NuGet redirection and package retrieval errors in Visual Studio 2015

Yesterday I have experience that I tried to install NuGet Package but an error occurred while retrieving package metadata in Visual Studio 2015.


NugetError.01

After getting some try and catch. I found out that the VS2015 is configured to connect the API v3 of the NuGet.org. So I tried to add another one with the URL on API v2 of the NuGet.org and I am then able to install any NuGet package. So I think that if you hit into the same error, this is a good to try.

NugetSetting.01


NugetSuccess.01

 

Useful links to learn Windows 10 and VS2015

images images
I am sure that you all are new to Win10 and VS2015. You may be looking for learning resource. Here I listed some of the sample site for you and so you could get some learning on these 2 new products.

Opportunity URLs Remarks
Developer Tools Download https://www.visualstudio.com/ Download any Visual Studio skus, including VS 2015
Developer for Windows 10  -What’s New
Get Started
Design
Develop
Publish
https://dev.windows.com/en-us/getstarted/whats-new-windows-10/
https://dev.windows.com/en-us/getstarted/
https://dev.windows.com/en-us/design/
https://dev.windows.com/en-us/develop/
https://dev.windows.com/en-us/publish/
All the info developers may need to write apps
Windows 10 courses in MVA https://www.microsoftvirtualacademy.com/en-US/training-courses/getting-started-with-windows-10-for-it-professionals-10629/ Great site to get online courses on Windows 10
Channel https://channel9.msdn.com/windows/ Another great online resource for Windows 10 related videos
Windows 10 Jumpstart http://www.microsoftvirtualacademy.com/liveevents/preparing-your-enterprise-for-windows-10-as-a-service/ A live event on August 14th

Visual Studio 2015 is released

VS2015.is.born
VS2015.is.born

As many of you might know that VS2015 is already released on 20th July 2015. If you are MSDN Subscriptor, you could download and install it now. For the Team Foundation Server 2015, you might have to wait for a little bit longer.

Watch the keynote on demand below to learn about the latest features and technologies. You can also watch the Visual Studio developer team create an end-to-end solution for an open-source project and see how they tackled problems along the way.

For more Visual Studio 2015 deep dive videos, please visit https://channel9.msdn.com/Series/ConnectOn-Demand

To download Visual Studio 2015, please visit https://www.visualstudio.com/downloads/download-visual-studio-vs

For more information about Visual Studio 2015, please visit https://www.visualstudio.com/vs-2015-product-editions

Free online training access on WintellectNow for 21 days

Wintellectnow

WintellectNOW is an on demand training solution that delivers real-world ready-to-use knowledge, tools and techniques so individuals and businesses can expertly develop software, programs, apps and more.

We got a promote code to give away and it allows you to take any online training for 21 days of free access.

The promo code to share is: HKNUGMSTC315

To use the Promo Code follow these instructions:

  1. Go to www.wintellectNOW.com
  2. Click on the Sign up Now button.
  3. Select “Use Promo Code”
  4. Enter HKNUGMSTC315 in the Promo code box.
  5. Fill out the rest of the form.