zoukankan      html  css  js  c++  java
  • MVC中很奇怪的问题

    情况是这样的, 慢慢听我道来~

    新建了一个MVC 3的项目, 在HomeController中继承BaseController

    1 using System;
    2  using System.Collections.Generic;
    3  using System.Linq;
    4  using System.Web;
    5  using System.Web.Mvc;
    6  using System.Web.UI;
    7
    8  using Cloud.Config;
    9
    10  namespace UserCenter.Controllers
    11 {
    12 public class HomeController : BaseController
    13 {
    14 public HomeController()
    15 {
    16 }
    17
    18 //
    19 // GET: /Home/
    20  
    21 public ActionResult Index()
    22 {
    23 return View();
    24 }
    25
    26 }
    27 }

    BaseController代码如下

    using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Web;
     using System.Web.Mvc;
     using System.Web.UI;
     using Cloud.Config;

     namespace UserCenter.Controllers
    {
    /// <summary>
    /// 基础
    /// </summary>
      public class BaseController : Controller
    {
    public BaseController()
    {
    if(Cookie("login") == null)
    {
              // 这地方报错, 未将对象引用设置到对象的实例。
    Response.Redirect(Url.Action("Login", "Account"));

              // 这地方不报错
              System.Web.HttpContext.Current.Response.Redirect(Url.Action("Login", "Account"));
    }
    }
      }
    }

    命名里的为啥就要补全? 简写语法不报错, 但是执行的时候就报错了

    我已经引用了, 如果没引用报错我认了, 但这问题真的很崩溃

  • 相关阅读:
    2013年10月17日 搬出来了
    如何与领导相处
    WEB系统开发
    C++ 常用术语(后续补充)
    C++ 构造函数放置默认转换explicit关键字(2)
    工作与生活
    C++类型转化分析(1)
    (一)win7下cocos2d-x 21 + vs2010
    为了生活
    iOS
  • 原文地址:https://www.cnblogs.com/yangyunzhou/p/1949601.html
Copyright © 2011-2022 走看看