Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items

北战南征 提交于 2019-12-07 14:16:23

问题


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

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

view:

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

controller:

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

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

view:

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

controller:

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

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

view:

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

controller:

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

or

view:

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

controller:

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

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


回答1:


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

Get object out of List< Tuple < object1, object2 > > and store in ViewModel

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!



来源:https://stackoverflow.com/questions/2695134/asp-net-mvc-2-net-4-0-error-when-view-model-type-is-tuple-with-more-than-4-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!