IE 会触发服务器错误,但 Firefox 不会

发布于 2024-10-13 04:38:32 字数 1622 浏览 2 评论 0原文

我有一个 RenderPartial 使 IE 出现黄色屏幕,

int addLocations = Model.Options.OfType<myOrderRowOption>().Single().AdditionalLocationsCount;

错误是: 异常详细信息:System.InvalidOperationException:序列不包含元素

FireFox 可以正常渲染。服务器端错误如何受到正在处理的浏览器的影响? (这不是回发 - 它发生在第一次调用视图时)。

后续:

好的...所以我清理了代码,使其更加美观,并且错误情况不再存在。 PartialView 的基本要点是填充一个表单,其中 orderRow 可以容纳 2 种不同类型的输入 - 一个单选按钮组,也可能是一个文本框。

最初,我有 2 个单独的 FOREACH 循环来迭代所有选项,并写出第一个中的单选按钮和第二个中的文本框。 (在每个循环内都有一个“If OptionType”测试。

我将其更改为 1 FOREACH 循环并使用 ELSE 分支。这清除了错误条件,但我仍然没有看到服务器端条件如何受到浏览器的影响非回发条件。

此代码结构有效 - 下面的注释详细说明了与原始错误条件的差异。

<div class="showOrderRow">
    <%string isChecked = "";
      foreach (var option in WebinarFacade.Instance.GetOptions(Model.Webinar))
      {

          isChecked = (int)Model.RegistrationType == option.ID ? "checked" : "";


          var optionType = option.GetType();
          if (optionType.Name == "Option")
          {%>
    <input type="radio" ... />
    <%
       } 

// originally this foreach loop ended and a started
//a 2nd one with a test that would exlcude the radio buttons
//if (optionType.Name != "Option")
       else
       {//point of original error
       int addLocations = Model.Options.OfType<myOrderRowOption>().Single().optionCount;
    %>
    <br />
        <h5>
            Additional Locations</h5>
            <input type="text" value="<%=addLocations%>" );'
                name="Count<%=Model.Order.ID %>" 
    <%
       }
 }
</div>

I have a RenderPartial that yellow screens IE at this line

int addLocations = Model.Options.OfType<myOrderRowOption>().Single().AdditionalLocationsCount;

error is:
Exception Details: System.InvalidOperationException: Sequence contains no elements

FireFox renders it fine. How can a server-side error be influenced by which browser is being addressed? (this isn't a postback - it's happening on the first-time call to the view).

Followup:

Ok...so i cleaned up the code to make it a little more presentable and the error condition no longer existed. The basic gist of the PartialView is populating a form where the orderRow can hold 2 different types of inputs - a radio button group and possibly a textbox.

Originally i had 2 separate FOREACH loops to iterate thru all option and wrote out the radio buttons in the first and the textbox in the 2nd. (with a 'If OptionType' test inside each loop.

I changed that to 1 FOREACH loop and used the ELSE branch instead. That cleared the error condition but I'm still not seeing how server-side conditions could be influenced by the browser in a non-postback condition.

this code structure works - comments below detail the differences from the original error condition.

<div class="showOrderRow">
    <%string isChecked = "";
      foreach (var option in WebinarFacade.Instance.GetOptions(Model.Webinar))
      {

          isChecked = (int)Model.RegistrationType == option.ID ? "checked" : "";


          var optionType = option.GetType();
          if (optionType.Name == "Option")
          {%>
    <input type="radio" ... />
    <%
       } 

// originally this foreach loop ended and a started
//a 2nd one with a test that would exlcude the radio buttons
//if (optionType.Name != "Option")
       else
       {//point of original error
       int addLocations = Model.Options.OfType<myOrderRowOption>().Single().optionCount;
    %>
    <br />
        <h5>
            Additional Locations</h5>
            <input type="text" value="<%=addLocations%>" );'
                name="Count<%=Model.Order.ID %>" 
    <%
       }
 }
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文