Request.IsAuthenticated不能在IE中重复部分视图MVC3

时间:2012-08-10 12:24:36

标签: asp.net-mvc-3

我对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>  
}

1 个答案:

答案 0 :(得分:2)

我会仔细检查渲染的标记是否有效。你的一个ID可能是重复的,并且IE只是踢它。

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