ASPNET MVC3技术要点(6)
发布时间:2021-06-06
发布时间:2021-06-06
ASPNET MVC3技术要点
3.1
接收输入:
3.1.1 从上下文对象(context)中提取数据
{
public ActionResult Info()
// Access various properties from context objects string url = Request.Url.ToString(); string serverName = Server.MachineName; string clientIP = erHostAddress; DateTime dateStamp = HttpContext.Timestamp; string userName = ;
ViewBag.Message = string.Format("URL = {0},serverName = {1},clientIP = {2},dateStamp = {3},userName = {4}",
url, serverName, clientIP, dateStamp, userName); return View(); }
3.1.2 通过动作函数参变量传递数据。
3.1.2.1 注意参变量必须实值,参变量可以取自Request.QueryString、
Request.Form,、RouteData.Values中的值,如果要使用引用变量必须为模型变量或模型变量集合。例如:
LogOn.cshtml视图代码如下:
@model SportsStore.WebUI.Models.LogOnViewModel @{
ViewBag.Title = "Admin: Log In";
Layout = "~/Views/Shared/_AdminLayout.cshtml"; }
<h1>Log In</h1>
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案