简体   繁体   English

为什么返回部分视图会影响我的样式应用于我的部分视图?

[英]Why does returning partial view affect my styles from being applied to my partial view?

So,所以,

I have bools for when to display a certain partial view and I noticed for one of my partial views, it displays correctly with the correct CSS styles and classes.我有什么时候显示某个局部视图的布尔值,我注意到我的一个局部视图,它使用正确的 CSS 样式和类正确显示。 However, my other partial view does not display correctly (I get no errors in console too) and I have narrowed it down to this line of code seeing how this makes the difference:但是,我的其他部分视图没有正确显示(我在控制台中也没有错误),我将其缩小到这行代码,看看这有什么不同:

 @Html.ActionLink(@Culture.GetString("ResetPasswordViaQuestionAnswer"), "GetUserName", "Account", new { style = "color:black; background: none;" }) 

OR或者

    <a href="@Url.Action("GetUserName", "Account")">@Culture.GetString("ResetPasswordViaQuestionAnswer")</a>

Whenever I use @Html.ActionLink or @Url.Action to call my action to return my partial view, the CSS style breaks.每当我使用 @Html.ActionLink 或 @Url.Action 调用我的动作来返回我的部分视图时,CSS 样式就会中断。 None of my classes get properly added to my inputs and form elements.我的任何类都没有正确添加到我的输入和表单元素中。

The above calls this action:上面调用这个动作:

        [AllowAnonymous]
        public ActionResult GetUserName()
        {
            LoginModel loginModel = new LoginModel();
            GetUserName getUserName = new GetUserName();
            loginModel.getUserName = getUserName;
            loginModel.DisplayResetPasswordDialog = true; 
            return PartialView("Login", loginModel);
        }

Which then goes to my Login partialview which inside a div contains:然后转到我的登录部分视图,其中 div 包含:

@if(Model.DisplayChangePasswordDialog == true){
                    @Html.Partial("PasswordExp",new ViewModels.PasswordChangeViewModel())
               }else if (Model.DisplayResetPasswordDialog == true){
                    @Html.Partial("ResetUserPassword", new ViewModels.GetUserName())
               }else{
                     @Html.Partial("_login", Model)
            }

Something in what I have done above is breaking the CSS styles and classes from being attached to my inputs.我在上面所做的事情是打破了 CSS 样式和类附加到我的输入。 The view is loaded but the view is loaded incorrectly.视图已加载,但视图加载不正确。 No styles or classes are applied.不应用任何样式或类。

Why?为什么?

You can't (or shouldn't) redirect to a partial view because you're not going to be getting your _Layout file that contains your css and js.您不能(或不应该)重定向到局部视图,因为您不会获得包含 css 和 js 的_Layout文件。

Instead you should redirect to a view containing your partial view.相反,您应该重定向到包含部分视图的视图。 That view should have a reference to your layout file.该视图应该引用您的布局文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM