Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items
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
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!
精彩评论