002..NET MVC实现自己的TempBag

时间:2022-09-03 15:42:16

原文链接:http://www.dotnetbips.com/articles/bc422c95-02cc-4d05-9c5c-fa89d0e78cc0.aspx

  1.前言

本来今天是想发那篇关于在Web API中关于路由的选择,但那一份是在公司翻译的,文件也在公司里。然后自己也比较感兴趣一些比较偏的知识。就像今天这一篇。在翻译的过程中,很多的文字自己感觉到十分的生硬,希望以后在自己看懂文章后,用文字将自己的理解表达出来,相信这样会更好。

  2. 开始

  在MVC中,相信大家都使用过ViewData或ViewBag(ViewBag是ViewData的一层封装),还一个用于在控制器向视图传递数据的方法-TempData,那我们能不能使用类似ViewBag包装ViewData的方式,使用TempBag实现动态查找值。我们可以创建一个类,如下

 public class TempBag: DynamicObject
{
TempDataDictionary tempData = null; public TempBag(TempDataDictionary tempdata)
{
this.tempData = tempdata;
} public override bool TryGetMember(GetMemberBinder binder, out object result)
{
try
{
//如果能找到相应的Key
if (tempData.Keys.Where(k => k == binder.Name).Count() > )
{
result = tempData[binder.Name];
return true;
}
else
{
result = "找不到值";
return false;
}
}
catch
{
result = "找不到值";
return false;
}
} public override bool TrySetMember(SetMemberBinder binder, object value)
{
try
{
tempData[binder.Name] = value;
return true;
}
catch
{
return false;
}
}
}

DynamicObject类位于System.Web.Mvc下,使用DynamicObject能够创建自己的动态对象。自己的类需要继承DynamicObject类,重写里面的三个方法:TrySetMember、TryGetMember、TryInvokeMember,前面两个方法用于设置和获取属性的实现,最后一个方法用于动态方法的调用,这里就不作介绍。

3.控制器中代码

 public class TempDataController : Controller
{ dynamic tempBag = null; public TempDataController()
{
tempBag = new TempBag(TempData);
} public ActionResult Index()
{
tempBag.Message = "一个很好的结果";
return View();
} }

在实例化控制器的时候,将它的一个动态对象实例化为我们自己定义的类的类型。控制器的构造函数中,传递TempData作为参数,那么我们在自己类中重写的两个方法分别对应为TempData设置和获取值。

4.在视图面的代码

 @{
Layout = null;
dynamic tempBag = new TempBag(TempData);
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<p>@@tempBag.Message的值为: @tempBag.Message</p>
<p>@@TempData["Message"]的值为: @TempData["Message"]</p>
</div>
</body>
</html>

如果没差错,那显示的结果如下图

aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCABjAYcDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD708S6LqOoXdpdaZc20E0MUsLC6jZ1ZXMbcbWByDGPzNYFz4P8S3sTxS3+lCOQbW2W8ucd8Zc16t/wgq/9BnUvyg/+NUf8IKv/A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ACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z" alt="" />

在视图页面,也需要创建一个TempBag的对象,这样才能访问到TempData对象。我们也能看到,使用@TempData["Message"]也能访问到我们定义的值,从这一侧面也表示,我们也只是为了动态访问TempData创建自己的类TempBag,就好像ViewBag之于ViewData。

002..NET MVC实现自己的TempBag的更多相关文章

  1. 002&period;Create a web API with ASP&period;NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp&period;net core mvc 创建一个 web api 程序】

    Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...

  2. 002&period;MVC开发方法和步骤--用一个简单的加法程序来演示

    MVC的工作原理: 注:ASP.NET MVC中的url 特殊:构成 http//....../控制器名/方法名 默认: 1.Url请求直接来到Controller中 2.Controller从Mod ...

  3. 002&period; Asp&period;Net Routing与MVC 之(基础知识):HttpModule 与 HttpHandler

    本文By 杨工. 一. Http.sys http.sys 从Win2003和WinXP SP2开始,就成为windows操作系统内核驱动程序,能够让任何应用程序通过它提供的接口,以http协议进行信 ...

  4. spring mvc返回json字符串的方式

    spring mvc返回json字符串的方式 方案一:使用@ResponseBody 注解返回响应体 直接将返回值序列化json            优点:不需要自己再处理 步骤一:在spring- ...

  5. 12、ASP&period;NET MVC入门到精通——HtmlHelper

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 HtmlHelper:是为了方便View的开发而产生 HtmlHelper的演变 普通首页超级链接为:<a href="/h ...

  6. MVC中几种常用ActionResult

    一.定义 MVC中ActionResult是Action的返回结果.ActionResult 有多个派生类,每个子类功能均不同,并不是所有的子类都需要返回视图View,有些直接返回流,有些返回字符串等 ...

  7. 了解ASP&period;NET MVC几种ActionResult的本质:JavaScriptResult &amp&semi; JsonResult

    在之前的两篇文章(<EmptyResult & ContentResult>和<FileResult>)我们剖析了EmptyResult.ContentResult和F ...

  8. &lbrack;转&rsqb;Spring3 MVC &plus; jQuery easyUI 做的ajax版本用户管理

    原文地址:http://www.iteye.com/topic/1081739 上周写了篇基于spring3.0.5 mvc 简单用户管理实例 ( http://www.iteye.com/topic ...

  9. Asp&period;Net MVC&lt&semi;一&gt&semi; &colon; 三层架构、MVC

    MVC.MVP.MVVM.Angular.js.Knockout.js.Backbone.js.React.js.Ember.js.Avalon.js.Vue.js 概念摘录 认清Android框架 ...

随机推荐

  1. IO多路复用,实现多线程监听

    服务端 import socket sk1 = socket.socket() sk1.bind(('127.0.0.1',8001)) sk1.listen() sk2 = socket.socke ...

  2. java&period;lang&period;NoClassDefFoundError&colon; com&period;umeng&period;analytics&period;MobclickAgent

    07-24 09:58:23.239: E/AndroidRuntime(29487): FATAL EXCEPTION: main 07-24 09:58:23.239: E/AndroidRunt ...

  3. HttpServlet

    HttpServlet的原理 HttpServlet抽象类中的(部分)方法 HttpServlet extends GenericServlet{ void service(ServletReques ...

  4. 20165220预备作业3 Linux安装及学习

    首先对于这第三次作业而言,给我的准备时间确实不多,因为过年回老家6天,没有办法及时的进行学习和思考,回到家中便草草的看了下相关操作跟教程从而完成了作业,这次主要是学习一些基础操作,为开学的Java学习 ...

  5. WebRTC 学习之 WebRTC 简介

    本文使用的WebRTC相关API都是基于Intel® Collaboration Suite for WebRTC的. 相关文档链接:https://software.intel.com/sites/ ...

  6. 百度AI--自然语言处理之Java开发

    参数: public class APIConstants { //设置APPID/AK/SK public static final String APP_ID = "108***&quo ...

  7. follow up2-20190426

    406. Minimum Size Subarray 同向双指针 https://www.lintcode.com/problem/minimum-size-subarray-sum/descript ...

  8. IE浏览器中找不到开发者工具

    ie浏览器不知道什么原因开发者工具不见了.打开以后在任务栏中显示打开了控制台,但是看不到. 解决方法 : F12 打开开发者工具后,按下 “ Ctrl + P ”

  9. ThinkPad如何修改fn键默认操作

    ThinkPad如何修改fn键默认操作 ThinkPad笔记本如何修改fn键默认操作 Fn键F1-F12

  10. 主攻ASP&period;NET&period;4&period;5&period;1 MVC5&period;0之重生&colon;*行政网站常用友情链接跳转javascript&lbrack;干货分享&rsqb;

    <!-----------------------------------> <script language="JavaScript" type="t ...