自定义参数输出错误

(1)创建一个Controller基类得控制器,就能够访问一些属性,而这些属性包括:Request,Response,RiuteData,HttpContext,Server等等得一些属性,下面就以案例说明。

示例:在控制器HomeController中得index进行一些代码编写,示例如下

public ActionResult Index(out int a)
        {
            //string userName = User.Identity.Name;

            //string serverName = Server.MachineName;

            //string clientIP = Request.UserHostAddress;

            //DateTime dateStamp = HttpContext.Timestamp;

            //string oldProductName = Request.Form["01dName"];

            //string newProductName = Request.Form["NewName"];

            //ViewBag.Message = "本机的IP是:" + clientIP;

            ViewBag.Title = "欢迎来到MVC的世界!";
            a = 1;
            ViewBag.Num = a;
            return View();
        }

(2)下一步就是在view下面得index视图中进行代码编写,index视图得代码如下

@{ 
    ViewBag.Title = "MyView";
}

<h2>MyView</h2>
Message:@ViewBag.Message<br/>
<br/>
Num:@ViewBag.Num

(3)代码写完了,就进行程序运行,运行得结果如下

而这个呢?就是我们自定义的参数输出错误。

猜你喜欢

转载自blog.csdn.net/qqj3066574300/article/details/83617288