悬赏园豆:50
[已关闭问题]
RT:<br><b><br>我在使用扩展方法的时候``` 他报了个这个错误`由于水平有限……So<br><br>请各位大大 帮帮 忙呀` 我把 代码 贴上来 请大家看下的哈!!!</b><br><br>这个是扩展方法<br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><img src="/Images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> IndexHtmler<br><img src="/Images/OutliningIndicators/ExpandedBlockStart.gif" id="Codehighlighter1_36_1399_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_36_1399_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_36_1399_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_36_1399_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedBlock.gif" id="Codehighlighter1_36_1399_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_36_1399_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_36_1399_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_36_1399_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_36_1399_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_36_1399_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> LinkList(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);"> HtmlHelper helper, </span><span style="color: rgb(0, 0, 255);">object</span><span style="color: rgb(0, 0, 0);"> obj,TakeRec tr)<br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_131_182_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_131_182_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_131_182_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_131_182_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_131_182_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_131_182_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_131_182_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_131_182_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_131_182_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_131_182_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> getDataList(obj,tr);<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> getDataList(</span><span style="color: rgb(0, 0, 255);">object</span><span style="color: rgb(0, 0, 0);"> obj,TakeRec getRec)<br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_260_1305_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_260_1305_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_260_1305_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_260_1305_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_260_1305_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_260_1305_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_260_1305_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_260_1305_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_260_1305_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_260_1305_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (obj </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Exception(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">对象不能为空</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (obj </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"> IEnumerable</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">)<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Exception(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">对象不能序列化</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> StringBuilder sb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringBuilder();<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> ISingleResult</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> objList </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ((ISingleResult</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">)obj);<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> IOrderedEnumerable</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> resList </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (getRec </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> TakeRec.Top)<br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_747_888_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_747_888_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_747_888_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_747_888_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_747_888_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_747_888_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_747_888_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_747_888_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_747_888_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_747_888_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> resList </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (IOrderedEnumerable</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">)objList.Take(</span><span style="color: rgb(128, 0, 128);">4</span><span style="color: rgb(0, 0, 0);">).OrderByDescending(o </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> o.LinkOrder);<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_918_1049_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_918_1049_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_918_1049_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_918_1049_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_918_1049_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_918_1049_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_918_1049_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_918_1049_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_918_1049_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_918_1049_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> resList </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (IOrderedEnumerable</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">mvc_GetAllMvc_LinksResult</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">)objList.Take(</span><span style="color: rgb(128, 0, 128);">4</span><span style="color: rgb(0, 0, 0);">).OrderBy(o </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> o.LinkOrder);<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">foreach</span><span style="color: rgb(0, 0, 0);"> (var i </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> resList)<br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_1101_1233_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1101_1233_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1101_1233_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1101_1233_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_1101_1233_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1101_1233_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1101_1233_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1101_1233_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_1101_1233_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_1101_1233_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> sb.AppendFormat(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);"><li><div><a href='{0}' target='_blank'>{1}</a></div></li></span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, i.LinkUrl, i.LinkName);<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> objList </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> sb.ToString();<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> <br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">enum</span><span style="color: rgb(0, 0, 0);"> TakeRec<br><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_1349_1393_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1349_1393_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1349_1393_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1349_1393_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_1349_1393_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1349_1393_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1349_1393_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1349_1393_Open_Text').style.display='inline';" align="top"> </span><span id="Codehighlighter1_1349_1393_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_1349_1393_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> Top,<br><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> Bot<br><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br><img src="/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"> }<br><br><b>下面是调用的(我跟踪了下 好象是第2次调用 就报那个错了)<br>请大大们帮忙解决下 谢谢!!!</b><br><ul> <br> <% =Html.LinkList(ViewData.Model,IndexHtmler.TakeRec.Top)%><br></ul><br><ul><br> <% =Html.LinkList(ViewData.Model,IndexHtmler.TakeRec.Bot)%><br></ul><br><br><br><b>这个是控制器的东西:</b><br> public class IndexController : Controller<br> {<br> public ActionResult Index()<br> {<br> Mvc_LinksDataContext obj = new Mvc_LinksDataContext();<br> ISingleResult<mvc_GetAllMvc_LinksResult> list = (ISingleResult<mvc_GetAllMvc_LinksResult>)obj.mvc_GetAllMvc_Links();<br> ViewData["Title"] = "My LinqDemo Of Mvc";<br> return View("../Index", list);<br> }<br> }<br><br><b>LINQ TO SQL 采用了 存储过程的。。。</b></span></span><span id="Codehighlighter1_36_1399_Open_Text"><span style="color: rgb(0, 0, 0);"><b>mvc_GetAllMvc_LinksResult 这个就是。。。<br><br>帮帮忙 谢谢!</b><br></span></span><span id="Codehighlighter1_36_1399_Open_Text"><span style="color: rgb(0, 0, 0);"><br></span></span></div><br>
问题补充:
提示的错误 就是 我在调用
我的扩展方法的 时候`
他就 出这个 错了 !!!
---------------------------------------------------
[无法枚举查询结果多次]
阳光囧男
|
菜鸟二级
|
园豆:
215
提问于:2008-08-10 15:47