方式一

(V:视图)

 @{
Layout = null;
} <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@Model.SName</td>
</tr>
</table>
</div>
</body>
</html>

(C:控制器)

         public ActionResult ShowCustomer()
{
Customer customer = new Customer() {Id=5,Age=18,SName="Alex",Email="543210@qq.com" };
return View(customer);
}

方式二

(V:视图一)

 @{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@Model.SName</td>
</tr>
</table>
</div>
</body>
</html>

(V:视图二)

 @{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@ViewData.Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@ViewData.Model.SName</td>
</tr>
</table>
</div>
</body>
</html>

(C:控制器)

         public ActionResult showcustomer()
{
Customer customer = new Customer() { Id = 5, Age = 18, SName = "Alex", Email = "543210@qq.com" };
ViewData.Model = customer;
return View();
}

Asp.Net MVC强类型页面获取值几种方式的更多相关文章

  1. ASP.NET MVC教程四:ASP.NET MVC中页面传值的几种方式

    准备 在Models文件夹里面新添加Student实体类,用来模拟从Controller向View传递数据,Student类定义如下: using System; using System.Colle ...

  2. ASP.NET MVC之下拉框绑定四种方式(十)

    前言 上两节我们讲了文件上传的问题,关于这个上传的问题还未结束,我也在花时间做做分割大文件处理以及显示进度的问题,到时完成的话再发表,为了不耽误学习MVC其他内容的计划,我们今天开始好好讲讲关于MVC ...

  3. asp.net mvc表单提交的几种方式

    asp.net MVC中form提交和控制器接受form提交过来的数据 MVC中form提交和在控制器中怎样接受 1.cshtml页面form提交2.控制器处理表单提交数据4种方式方法1:使用传统的R ...

  4. ASP.NET MVC 方法View返回的两种方式

    1.参数为字符串类型 例如我们在地址栏输入http://localhost:56431/Test/Index,会查找TestController类下的Index方法并执行,如下图 当我们返回字符串类型 ...

  5. 学习ASP.NET MVC(七)——我的第一个ASP.NET MVC 查询页面

    在本篇文章中,我将添加一个新的查询页面(SearchIndex),可以按书籍的种类或名称来进行查询.这个新页面的网址是http://localhost:36878/Book/ SearchIndex. ...

  6. Asp.net MVC 中Controller返回值类型ActionResult

    [Asp.net MVC中Controller返回值类型] 在mvc中所有的controller类都必须使用"Controller"后缀来命名并且对Action也有一定的要求: 必 ...

  7. ASP.NET MVC传递Model到视图的多种方式总结

    ASP.NET MVC传递Model到视图的多种方式总结 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel T ...

  8. ASP.NET MVC传递Model到视图的多种方式之通用方式的使用

    ASP.NET MVC传递Model到视图的多种方式总结——通用方式的使用 有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData Vi ...

  9. ASP.NET MVC中Area的另一种用法

    ASP.NET MVC中Area的另一种用法 [摘要]本文只是为一行代码而分享 context.MapRoute("API", "api/{controller}/{ac ...

随机推荐

  1. jsp表单更新数据库

    和插入语句相似,表单传值,在另一个页面接收数据并连接数据库进行更新: 语句如下: <% request.setCharacterEncoding("UTF-8"); Stri ...

  2. 挑战常规 -- 为什么不要再用cookie作为储存?

    不要使用cookie当存储 Cookie 是什么? Cookie 由浏览器储存在本地,每次访问目标网址会带上的请求头,服务器可以通过Set-Cookie响应头设置Cookie. Cookie的用途 由 ...

  3. [转]JVM系列二:GC策略&内存申请、对象衰老

    原文地址:http://www.cnblogs.com/redcreen/archive/2011/05/04/2037056.html JVM里的GC(Garbage Collection)的算法有 ...

  4. MongoDB 最近遇到的几个小问题

    (1)连接数据库时报错 ERROR Topshelf.Hosts.ConsoleRunHost.Run An exception occurred System.TimeoutException: A ...

  5. client-go向controller进发---code-generator实现

    这个时间长了,可能前后想了一周时间. 哎,其它不怪,只怪go的工程包管理这几年太混乱, 而国内下载资源也太漫长. 现在,只能坚持 使用go mod了. 但在使用code-generator时,go m ...

  6. Hive 读书札记

    把数据从一个关系型数据库直接导入 Hive,使用 Sqoop.

  7. [C2W3] Improving Deep Neural Networks : Hyperparameter tuning, Batch Normalization and Programming Frameworks

    第三周:Hyperparameter tuning, Batch Normalization and Programming Frameworks 调试处理(Tuning process) 目前为止, ...

  8. blue bossa

    blue bossa

  9. angular 多路由模块新建组件的方法

    More than one module matches. Use skip-import option to skip importing the component into the closes ...

  10. MySQL的delete误操作的快速恢复方法

    1. 根据误操作时间定位binlog位置找到数据库的binlog存放位置,当前正在使用的binlog文件里面就有我们要恢复的数据.一般生产环境中的binlog文件都是几百M乃至上G的大小,我们不能逐行 ...