﻿# 解決 ASP.NET MVC 專案無法在 VS2008 使用快速鍵的問題

當在你的 Visual Studio 2008 同時安裝 ASP.NET MVC 1.0 與 2.0 Beta 的版本時，很有可能會遇到開啟 ASP.NET MVC 2.0 專案時無法使用快速鍵(Shortcuts)的問題，這個問題是因為你之前在安裝 ASP.NET MVC 1.0 時快速鍵就已經註冊進 Visual Studio 之中，導致安裝 ASP.NET MVC 2.0 Beta 時無法註冊成功，這時只要做個在 \[工具\] / \[選項\] 的 \[鍵盤\] 重新設定即可。

當你在 ASP.NET MVC 2.0 專案的 Controller Action 裡按下 Ctrl + M + Ctrl + G 時會出現以下訊息：

![The key combination (Ctrl+M, Ctrl+G) is bound to command (Go To &View) which is not currently available.](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/ce1b03d0227130518356-image.png "The key combination (Ctrl+M, Ctrl+G) is bound to command (Go To &View) which is not currently available.")

在 \[Tools\] / \[Options\] 的 \[Keyboard\] 的設定中，在 Show commands containing: 欄位輸入 **GoToView**

 ![](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/dab54c080671c7c87cfb-image.png)

這是你會搜尋出兩個完全一樣的巨集名稱，其實一個是 ASP.NET MVC 1.0 用的，另一個是 ASP.NET MVC 2.0 Beta 用的，而其中已經已經註冊了快速鍵，另一個則沒有，註冊的那個就是 ASP.NET MVC 1.0 的版本。

像我們最近已經開使用 ASP.NET MVC 2.0 開發專案，所以當要開發 ASP.NET MVC 2.0 專案時就可以將快速鍵指定(Assign)到另一個同名的巨集上即可。但除了 **GoToView** 之外還有 **GoToController** 這個巨集要設訂，修改快速鍵的流程如下：

1.  先輸入 Show commands containing 搜尋出所需巨集

1.  GoToView
2.  GoToController

3.  點選另一個同名巨集
4.  選取 Use new shortcut in 欄位

1.  GoToView  →   選取 **Text Editor**
2.  GoToController  →   選取 **HTML Editor Source View**

6.  用滑鼠點擊 Press shortcut keys 欄位，並透過鍵盤按下快速鍵 ( Ctrl + M , Ctrl + G )
7.  用滑鼠點擊 \[Assign\] 按鈕，再按下 \[OK\] 即可完成設定

分別設定的示意圖如下：

![image](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/6fcc709fe53f684b035d-image.png "image")

![image](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/4be68f04bd0621140012-image.png "image")
