为什么我必须进行页面刷新才能让我的Telerik TabStrip在ASP.Net MVC 4中更新?

时间:2021-07-21 07:27:08

I am trying to show/hide Tabs depending on a user access level that I pass to my View that contains a Telerik tabStrip as shown below:

我试图显示/隐藏选项卡,具体取决于我传递给包含Telerik tabStrip的View的用户访问级别,如下所示:

@{  Html.Telerik().TabStrip()
.Name("Main_Tabstrip")
.Items(tabstrip =>
{
    tabstrip.Add()
        .Visible((int)ViewData["UserLevel"] < 2)
        .Text("Topic A")
        .LoadContentFrom("_TopicATab", "TopicA");
    tabstrip.Add()
        .Visible((int)ViewData["UserLevel"] < 2)
        .Text("Topic B")
        .LoadContentFrom("_TopicBTab", "TopicB");
    tabstrip.Add()
        .Visible((int)ViewData["UserLevel"] < 2)
        .Text("Topic C")
        .LoadContentFrom("_TopicCTab", "TopicC");
})

However, when I call the Action that generates the View after a change in user status, although the View appears to update (I can step through it and see the UserLevel change) the Tab visibility remains as it was on the first rendering of the view.

但是,当我调用在用户状态更改后生成View的Action时,虽然View似乎更新(我可以单步执行并查看UserLevel更改),但Tab可见性仍然保留在第一次呈现视图时。

If I subsequently refresh the Page either in the browser or via a JavaScript location.reload() call then the Tab Visibility works fine.

如果我随后在浏览器中或通过JavaScript location.reload()调用刷新页面,则Tab Visibility工作正常。

Additional information: The Action referred to above calls View() to Render the full page that contains the above View.

附加信息:上面提到的Action调用View()来渲染包含上述View的整个页面。

Although I was able to work around the problem on this occasion by doing a page reload in JavaScript, I would really like to know why this was necessary and would appreciate any suggestions or solutions.

虽然我能够通过在JavaScript中进行页面重新加载来解决这个问题,但我真的想知道为什么这是必要的,并且会感谢任何建议或解决方案。

1 个解决方案

#1


1  

(I am posting this as an answer, since it is too long for a comment.)

(我发布这个作为答案,因为评论太长了。)

Sorry, I should have been more specific. I meant from where in the page are you calling the action?

对不起,我应该更具体一点。我的意思是你在页面中的哪个位置调用动作?

Your action returns some html (generated from the view) that is returned to the browser and one of two things happen depending on how the action was called:

您的操作会返回一些返回给浏览器的html(从视图生成),并且根据调用操作的方式发生以下两种情况之一:

(1) The whole page is replaced (and the browser might change the displayed address depending on the request verb)

(1)替换整个页面(浏览器可能会根据请求动词更改显示的地址)

(2) A part of the page, for example the content of a div, is replaced.

(2)替换页面的一部分,例如div的内容。

To accomplish (1) you will probably use a call to Html.ActionLink or an old fashioned anchor tag. I would however advise you to use (2) instead, since it can give better UX, but it is harder to do. You would make an Ajax call, either via jQuery's ajax method, or an Ajax.ActionLink call.

要完成(1),您可能会使用Html.ActionLink或旧式锚标记。但是我建议你使用(2)代替,因为它可以提供更好的用户体验,但它更难做到。您可以通过jQuery的ajax方法或Ajax.ActionLink调用进行Ajax调用。

So basically my counter-question was about which of these you are using. My suspicion is that you are requesting the action, but not writing the response anywhere. Can you perhaps show code for the action and the rest of the view, or reduce it to a minimal example to paste here?

所以基本上我的反问题是你正在使用哪些。我怀疑你是在请求采取行动,而不是在任何地方写回应。您是否可以显示操作的代码和视图的其余部分,或者将其缩小到最小的示例以粘贴到此处?

More to the point of your question though, I have looked around a little and you are right that showing/hiding the tabs with javascript is not supported out-of-the-box. I did however find these two posts which might still help you http://www.aspnetwiki.com/page:extending-the-telerik-mvc-client-api http://www.aspnetwiki.com/telerik-mvc:dynamically-add-a-tab-to-the-tabstrip

更重要的是你的问题,我已经看了一下,你是正确的,用javascript显示/隐藏标签是不支持开箱即用的。然而,我确实发现这两个帖子可能仍然可以帮助你http://www.aspnetwiki.com/page:extending-the-telerik-mvc-client-api http://www.aspnetwiki.com/telerik-mvc:dynamically -add-A-片 - 的-标签栏

#1


1  

(I am posting this as an answer, since it is too long for a comment.)

(我发布这个作为答案,因为评论太长了。)

Sorry, I should have been more specific. I meant from where in the page are you calling the action?

对不起,我应该更具体一点。我的意思是你在页面中的哪个位置调用动作?

Your action returns some html (generated from the view) that is returned to the browser and one of two things happen depending on how the action was called:

您的操作会返回一些返回给浏览器的html(从视图生成),并且根据调用操作的方式发生以下两种情况之一:

(1) The whole page is replaced (and the browser might change the displayed address depending on the request verb)

(1)替换整个页面(浏览器可能会根据请求动词更改显示的地址)

(2) A part of the page, for example the content of a div, is replaced.

(2)替换页面的一部分,例如div的内容。

To accomplish (1) you will probably use a call to Html.ActionLink or an old fashioned anchor tag. I would however advise you to use (2) instead, since it can give better UX, but it is harder to do. You would make an Ajax call, either via jQuery's ajax method, or an Ajax.ActionLink call.

要完成(1),您可能会使用Html.ActionLink或旧式锚标记。但是我建议你使用(2)代替,因为它可以提供更好的用户体验,但它更难做到。您可以通过jQuery的ajax方法或Ajax.ActionLink调用进行Ajax调用。

So basically my counter-question was about which of these you are using. My suspicion is that you are requesting the action, but not writing the response anywhere. Can you perhaps show code for the action and the rest of the view, or reduce it to a minimal example to paste here?

所以基本上我的反问题是你正在使用哪些。我怀疑你是在请求采取行动,而不是在任何地方写回应。您是否可以显示操作的代码和视图的其余部分,或者将其缩小到最小的示例以粘贴到此处?

More to the point of your question though, I have looked around a little and you are right that showing/hiding the tabs with javascript is not supported out-of-the-box. I did however find these two posts which might still help you http://www.aspnetwiki.com/page:extending-the-telerik-mvc-client-api http://www.aspnetwiki.com/telerik-mvc:dynamically-add-a-tab-to-the-tabstrip

更重要的是你的问题,我已经看了一下,你是正确的,用javascript显示/隐藏标签是不支持开箱即用的。然而,我确实发现这两个帖子可能仍然可以帮助你http://www.aspnetwiki.com/page:extending-the-telerik-mvc-client-api http://www.aspnetwiki.com/telerik-mvc:dynamically -add-A-片 - 的-标签栏