0

我对 MVC3 应用程序有奇怪的问题。该应用程序在 Firefox 和 Chrome 上按预期运行,但在 IE 上不运行。

我有一个在页面上循环重复的部分视图。在局部视图的底部,我正在检查 Request.IsAuthenticated。如果经过身份验证,应该显示一个 ajax 表单。这适用于除 IE 之外的所有浏览器。在 IE 中,如果呈现的局部视图有多个实例,则表单不会出现(即使用户已登录)。

我在下面附上了部分视图代码。表格就在底部。

有没有其他人有类似的问题?任何帮助或想法都会很棒。谢谢

@using HERE_MVC.Extenstions
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
@model HERE_MVC.Models.TilesModel
@{
    Layout = String.Empty; 
}
@foreach (var t in Model.NearestTiles)
{     
    <div id="div_tile @t.TileId" style="float: left; height: 235px; width: 300px; border: 0px solid black; margin: 5px;
        background-color: #DDDDDD;">
        <div id="tile @t.TileId" style="background-image: url(@Url.Action("GetTileBgImageWithCache", "Account", new { userName = @t.aspnet_Users.UserName })); background-repeat:no-repeat; height: 200px; width: 300px; border: 0px solid black;">
            @t.aspnet_Users.UserName
            <br />
            @t.Title
            <br />
            @t.Quote1
            <br />
            @t.UpdatedDateTime
        </div>
        <div id="collectbtn @t.TileId" style="padding-top: 5px;">
            @Html.ActionImage("Profile", "Home", new { userName = @t.aspnet_Users.UserName }, "~/content/img/Profile-Icon.jpg", "View Profile", "25")
            @if (Request.IsAuthenticated)
            {
                if (@User.Identity.Name == @t.aspnet_Users.UserName)
                {
                }
                else if (!Model.CheckAlreadyFollowing(@User.Identity.Name, @t.aspnet_Users.UserName))
                {         
                @Ajax.ActionImageLink("../content/img/add.jpg", "Collect Tile", "25", "imgOn1" + @t.aspnet_Users.UserName, "AddFollowedUser", "Home", new { userToFollowName = @t.aspnet_Users.UserName }, new AjaxOptions { HttpMethod = "POST", OnSuccess = "  $(#imgOn1" + @t.aspnet_Users.UserName + ").hide();" })
                }
                else
                {  
                @Ajax.ActionImageLink("../content/img/minus.jpg", "Drop Tile", "25", "imgOff2" + @t.aspnet_Users.UserName, "UnFollow", "Home", new { userToUnFollowName = @t.aspnet_Users.UserName }, new AjaxOptions { HttpMethod = "POST" })
                }
            }
            <a href="http://www.facebook.com/sharer.php?u=@t.ShareLink&t=%22+encodeURIComponent(document.title)" onclick="PopupCenter('http://www.facebook.com/sharer.php?u=@t.ShareLink&t=%22+encodeURIComponent(document.title)', 'NearRoar - Facebook',680,400); return false;" class="pin-it-button" count-layout="none">
                <img src="../../Content/img/Facebook-share.jpg" width="25px" alt="Facebook share" /></a>
            <a href="http://pinterest.com/pin/create/button/?url=@t.ShareLink&media=@t.PintrestShareImage&description=@t.PinterestShareText" onclick="PopupCenter('http://pinterest.com/pin/create/button/?url=@t.ShareLink&media=@t.PintrestShareImage&description=@t.PinterestShareText', 'NearRoar - Pin It',600,400); return false;" class="pin-it-button" count-layout="none" target="_blank">
                <img border="0" src="../../Content/img/pintrest.jpg" title="Pin It" width="25px" /></a>
            <a href="https://twitter.com/share" class="twitter-share-button" data-hashtags="@t.TwitterHashTag,NearRoar" data-url="@t.ShareLink" data-count="none" data-lang="en">
            </a>
            <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
        </div>
        <div class="msg_list">
            <p class="msg_head @t.TileId">
                Comments (<span id='commentCount '@t.TileId>@t.CommentLines.Count</span>)</p>
            <div class="msg_body">
                @foreach (var c in t.CommentLines)
                {
                    <div class="clearfix">
                        <div class="msg_body_comment_item_image">
                            <img width="50" src="@Url.Action("GetImageWithCache", "Home", new { userName = @c.aspnet_Users.UserName })"/>
                        </div>
                        <div class="msg_body_comment_item_text">
                            @c.CommentLine1
                            <br />
                            @c.CommentTime
                        </div>
                    </div>
                }
                <div id="newComment @t.TileId">
                </div>
                <div id="formdiv @t.TileId">
                    @if (Request.IsAuthenticated)
                    {
                        <div>
                        @using (Ajax.BeginForm("Comment" + @t.TileId, "Home", new { tileId = @t.TileId }, new AjaxOptions { }, new { id = "form" + @t.TileId, name = "form" + @t.TileId }))
                        {
                        <fieldset>
                            @Html.TextBox("commentText " + @t.TileId, null, new { @class = "msg_body_comment_text_input", maxlength = 200 })
                            <input type="hidden" name="date" id="cmTimeHidden @t.TileId"  value="" />
                            <input type="hidden" name="commentText" id="commentTextHidden @t.TileId"  value="" />
                            <input type="submit" value="Post Comment" onClick="setHiddens(@t.TileId);setNewComment(@t.TileId);"/>
                        </fieldset>
                        }
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>  
}
4

1 回答 1

2

我会仔细检查呈现的标记是否有效。您的一个 ID 可能重复,而 IE 只是将其踢走。

更新:您有 4 个 ID 为 t.titleId 的元素。正如我上面所说,您在 HTML 页面上只能有一个特定的 ID。把它移到课堂上,一切都应该没问题。

于 2012-08-10T12:28:21.390 回答