Asp.net MVC 2 .NET 4.0错误时查看模型类型的元组超过4项 [英] Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items

查看:606
本文介绍了Asp.net MVC 2 .NET 4.0错误时查看模型类型的元组超过4项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建强类型视图在Asp.net MVC 2,.NET 4.0型号类型元组,我得到的错误时,元组有4个以上的项目

When I create strongly typed View in Asp.net mvc 2, .net 4.0 with model type Tuple I get error when Tuple have more than 4 items

示例1:   视图类型是元组LT;字符串,字符串,字符串,字符串> (4元),一切工作正常。

example 1: type of view is Tuple<string, string, string, string> (4-tuple) and everything works fine

查看:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web.Mvc.ViewPage<Tuple<string, string, string, string>>" %>

控制器:

var tuple = Tuple.Create("a", "b", "c", "d");
return View(tuple);

例2:   视图类型是元组LT;字符串,字符串,字符串,字符串,字符串&GT; (5元组),我有这样的错误:编译器错误信息: CS1003:语法错误,'&GT;预计

example 2: type of view is Tuple<string, string, string, string, string> (5-tuple) and I have this error: Compiler Error Message: CS1003: Syntax error, '>' expected

查看:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web.Mvc.ViewPage<Tuple<string, string, string, string, string>>" %>

控制器:

var tuple = Tuple.Create("a", "b", "c", "d", "e");
return View(tuple);

例如3   如果我的视图模型的类型是动态的,我可以同时使用4元和5元组并没有页面上没有错误。

example 3 if my view model is of type dynamic I can use both 4-tuple and 5-tuple and there is no error on page

查看:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

控制器:

dynamic model = new ExpandoObject();
model.tuple = Tuple.Create("a", "b", "c", "d");
return View(model);

查看:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

控制器:

dynamic model = new ExpandoObject();
model.tuple = Tuple.Create("a", "b", "c", "d", "e");
return View(model);

即使我有类似元组LT;字符串,元组LT;字符串,字符串,字符串&gt;中字符串&GT; 3元组和的项目之一,也是一个元组和在所有元组项之和大于4,我得到了同样的错误,元组LT;字符串,元组LT;字符串,字符串&gt;中字符串&GT; 正常工作

Even if I have something like Tuple<string, Tuple<string, string, string>, string> 3-tuple and one of the items is also a tuple and sum of items in all tuples is more than 4 I get the same error, Tuple<string, Tuple<string, string>, string> works fine

推荐答案

请查看:找对象出名单,其中,元组LT; object1,Object2的>>,并将其储存在强类型的视图模型

Please review: Get objects out of List< Tuple < object1, object2 > > and store them in Strongly Typed ViewModel

<一个href="http://stackoverflow.com/questions/4189730/get-object-out-of-list-tuple-object1-object2-and-store-in-viewmodel">Get从对象列表>,并存储在视图模型

通过这样做,你可以建立5个相关的表联接。你会(概率近乎确定性)结束与含5个对象(反映表)的元组。迭代直通的listoftuples并获得在每个元组中的对象5分开列出的项目。给他们打电话,我建议在5个独立的部分景色(如果你熟悉ASP MVC 2)。如果不是这样,我相信你会管理,反正。大约在很短的一段时间,我会希望尝试一下自己。我会的,肯定的,至少设置了三个表,可能是四个加盟。不过,我可以形象会有情况下有人将不得不参加至少五......尤其是,当数据库是高度规范化。更迭!

By doing so, you could set up a join with 5 related tables. You will (probability is bordering on certainty) end up with tuples containing 5 objects (reflecting the tables). Iterate thru the listoftuples and get the items in each tuple separated in 5 lists of objects. Call them as I suggested on 5 separate partial views (if you familiar with ASP MVC 2). If not, I do believe you will manage, anyway. In about a short while, I will hopefully try it out myself. I will, for sure, at least set up a join with three tables, possibly four. However, I can image that there will be circumstances somebody will have to join at least five ... especially, when the database is highly normalized. Succes!

这篇关于Asp.net MVC 2 .NET 4.0错误时查看模型类型的元组超过4项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆