///
/// 檢查特定Controller和Action是否存在
///
///控制器名稱
///動作名稱
/// 
public static bool IsControllerAndActionExist(string controller, string action)
{
    var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
    Type[] types = executingAssembly.GetTypes();
    Type type = types.Where(t => t.Name == controller + "Controller").SingleOrDefault();
    if (type != null && type.GetMethod(action) != null)
    {
        return true;
    }

    return false;
}

資料來源:http://stackoverflow.com/questions/7033428/how-to-make-sure-controller-and-action-exists-before-doing-redirect-asp-net-mvc

arrow
arrow
    全站熱搜

    小賢 發表在 痞客邦 留言(0) 人氣()